From fcffed23ada90e00cd8de359d1913c3c4ebfd697 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 29 Nov 2024 13:28:03 +0900 Subject: [PATCH] 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. --- ext/fiddle/pointer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/fiddle/pointer.c b/ext/fiddle/pointer.c index 00bd76e9..10a6cc70 100644 --- a/ext/fiddle/pointer.c +++ b/ext/fiddle/pointer.c @@ -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; }