Skip to content

Commit d1e6bf3

Browse files
committed
Do not depend on the evaluation order of C arguments
The evaluation order of C arguments is unspecified. `RSTRING_LEN(value)` would fail if the conversion to a String by `StringValuePtr(value)` is not done yet. Coverity Scan found this issue.
1 parent ffc4e98 commit d1e6bf3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/psych/psych_emitter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,12 @@ static VALUE scalar(
304304
tag = rb_str_export_to_enc(tag, encoding);
305305
}
306306

307+
const char *value_ptr = StringValuePtr(value);
307308
yaml_scalar_event_initialize(
308309
&event,
309310
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
310311
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
311-
(yaml_char_t*)StringValuePtr(value),
312+
(yaml_char_t*)value_ptr,
312313
(int)RSTRING_LEN(value),
313314
plain ? 1 : 0,
314315
quoted ? 1 : 0,

0 commit comments

Comments
 (0)