Skip to content

Commit

Permalink
Make embedded string length a long for VWA
Browse files Browse the repository at this point in the history
A short (2 bytes) will cause unaligned struct accesses when strings are
used as a buffer to directly store binary data.
  • Loading branch information
peterzhu2118 committed Jan 12, 2022
1 parent e28dbd0 commit 2d81a71
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/ruby/internal/core/rstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ struct RString {
/** Embedded contents. */
struct {
#if USE_RVARGC
unsigned short len;
long len;
/* This is a length 1 array because:
* 1. GCC has a bug that does not optimize C flexible array members
* (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
Expand Down
2 changes: 1 addition & 1 deletion test/-ext-/string/test_capacity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def capa(str)

def embed_header_size
if GC.using_rvargc?
2 * RbConfig::SIZEOF['void*'] + RbConfig::SIZEOF['short']
2 * RbConfig::SIZEOF['void*'] + RbConfig::SIZEOF['long']
else
2 * RbConfig::SIZEOF['void*']
end
Expand Down

0 comments on commit 2d81a71

Please sign in to comment.