diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-04-16 17:45:27 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-04-16 17:45:27 +0900 |
commit | fac814c2dc31afef272b45392a7389ef0bfa3a4f (patch) | |
tree | 403f732183e2a0191ea36042c978cb1e7be2d666 /regint.h | |
parent | 29e01c6f5f8901bdaab818dfd4699cfa2a86b8e6 (diff) |
Fix `PLATFORM_GET_INC`
On platforms where unaligned word access is not allowed, and if
`sizeof(val)` and `sizeof(type)` differ:
- `val` > `type`, `val` will be a garbage.
- `val` < `type`, outside `val` will be clobbered.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7723
Diffstat (limited to 'regint.h')
-rw-r--r-- | regint.h | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -319,9 +319,13 @@ RUBY_SYMBOL_EXPORT_BEGIN #define ONIG_LAST_CODE_POINT (~((OnigCodePoint )0)) +#define PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type) \ + ((void)sizeof(char[2 * (sizeof(val) == sizeof(type)) - 1])) + #ifdef PLATFORM_UNALIGNED_WORD_ACCESS # define PLATFORM_GET_INC(val,p,type) do{\ + PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type);\ val = *(type* )p;\ (p) += sizeof(type);\ } while(0) @@ -329,7 +333,10 @@ RUBY_SYMBOL_EXPORT_BEGIN #else # define PLATFORM_GET_INC(val,p,type) do{\ - xmemcpy(&val, (p), sizeof(type));\ + PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type);\ + type platform_get_value;\ + xmemcpy(&platform_get_value, (p), sizeof(type));\ + val = platform_get_value;\ (p) += sizeof(type);\ } while(0) |