Do not depend on the evaluation order of C arguments

The evaluation order of C arguments is unspecified.
`RSTRING_LEN(str)` would fails if the conversion to a String by
`StringValuePtr` is not done yet.

Coverity Scan found this issue.
This commit is contained in:
Yusuke Endoh 2024-11-29 13:28:03 +09:00
parent 5d156007f6
commit 6adc69c41c
Notes: git 2024-12-03 20:43:43 +00:00

View File

@ -827,7 +827,8 @@ rb_fiddle_ptr_read_mem(VALUE klass, VALUE address, VALUE len)
static VALUE
rb_fiddle_ptr_write_mem(VALUE klass, VALUE addr, VALUE str)
{
memcpy(NUM2PTR(addr), StringValuePtr(str), RSTRING_LEN(str));
const char *ptr = StringValuePtr(str);
memcpy(NUM2PTR(addr), ptr, RSTRING_LEN(str));
return str;
}