ruby-changes:70841
From: Peter <ko1@a...>
Date: Thu, 13 Jan 2022 02:01:21 +0900 (JST)
Subject: [ruby-changes:70841] 2d81a718ec (master): Make embedded string length a long for VWA
https://git.ruby-lang.org/ruby.git/commit/?id=2d81a718ec From 2d81a718eca679b9bf458beccf1e7a86b812c3e2 Mon Sep 17 00:00:00 2001 From: Peter Zhu <peter@p...> Date: Tue, 11 Jan 2022 15:19:39 -0500 Subject: Make embedded string length a long for VWA A short (2 bytes) will cause unaligned struct accesses when strings are used as a buffer to directly store binary data. --- include/ruby/internal/core/rstring.h | 2 +- test/-ext-/string/test_capacity.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ruby/internal/core/rstring.h b/include/ruby/internal/core/rstring.h index 4a8aa3f7d34..9f6dc845379 100644 --- a/include/ruby/internal/core/rstring.h +++ b/include/ruby/internal/core/rstring.h @@ -280,7 +280,7 @@ struct RString { https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rstring.h#L280 /** 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) diff --git a/test/-ext-/string/test_capacity.rb b/test/-ext-/string/test_capacity.rb index 583c98fca46..6b3172a46d3 100644 --- a/test/-ext-/string/test_capacity.rb +++ b/test/-ext-/string/test_capacity.rb @@ -66,7 +66,7 @@ class Test_StringCapacity < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_capacity.rb#L66 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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/