Skip to content

Commit fcffed2

Browse files
mamehsbt
authored andcommitted
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.
1 parent 444774c commit fcffed2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/fiddle/pointer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ rb_fiddle_ptr_read_mem(VALUE klass, VALUE address, VALUE len)
827827
static VALUE
828828
rb_fiddle_ptr_write_mem(VALUE klass, VALUE addr, VALUE str)
829829
{
830-
memcpy(NUM2PTR(addr), StringValuePtr(str), RSTRING_LEN(str));
830+
const char *ptr = StringValuePtr(str);
831+
memcpy(NUM2PTR(addr), ptr, RSTRING_LEN(str));
831832
return str;
832833
}
833834

0 commit comments

Comments
 (0)