summaryrefslogtreecommitdiff
path: root/internal/object.h
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2021-03-02 15:22:22 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2021-03-02 17:47:28 +0900
commit33dc0a070a515811e71fccbdc8cf0cd5a5dd784c (patch)
treed6ca5f2dd18cb8edba2de89e6ee682b43ad17680 /internal/object.h
parentf7c342f8759c9914e1216da29bd8d7b1b8c8c91b (diff)
downloadruby-33dc0a070a515811e71fccbdc8cf0cd5a5dd784c.tar.gz
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]
Diffstat (limited to 'internal/object.h')
-rw-r--r--internal/object.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/internal/object.h b/internal/object.h
index aa820128c7..2af90c1fdc 100644
--- a/internal/object.h
+++ b/internal/object.h
@@ -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