1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

RBASIC_SET_CLASS_RAW: follow strict aliasing rule

Instead of rather euphemistic struct cast, just reomve the const
qualifier and assign directly.  According to ISO/IEC 9899:2018 section
6.5 paragraph 7, `VALUE` and `const VALUE` are allowed to alias (but two
distinct structs are not, even when their structures are the same).
[Bug #17540]
This commit is contained in:
卜部昌平 2021-03-02 15:22:22 +09:00
parent f7c342f875
commit 33dc0a070a
Notes: git 2021-03-02 17:47:49 +09:00

View file

@ -47,8 +47,8 @@ MJIT_SYMBOL_EXPORT_END
static inline void
RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass)
{
struct { VALUE flags; VALUE klass; } *ptr = (void *)obj;
ptr->klass = klass;
const VALUE *ptr = &RBASIC(obj)->klass;
*(VALUE *)ptr = klass;
}
static inline void