Skip to content

Commit

Permalink
Do not depend on the evaluation order of C arguments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mame authored and hsbt committed Dec 10, 2024
1 parent 444774c commit fcffed2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/fiddle/pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit fcffed2

Please sign in to comment.