summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2024-11-29 13:33:34 +0900
committergit <svn-admin@ruby-lang.org>2024-12-04 01:35:29 +0000
commita0eb541e52f43bfb3a889b9a6a69f6f37d5b79a0 (patch)
tree8d5cc4b0a940f263815f96e5d3e52b00298df83a
parente539342f65e468fc7f926277eff61cb8b8a60622 (diff)
[ruby/psych] 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. https://github.com/ruby/psych/commit/d1e6bf323a
-rw-r--r--ext/psych/psych_emitter.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/ext/psych/psych_emitter.c b/ext/psych/psych_emitter.c
index 0c5875f343..3b7a367bd7 100644
--- a/ext/psych/psych_emitter.c
+++ b/ext/psych/psych_emitter.c
@@ -304,11 +304,12 @@ static VALUE scalar(
tag = rb_str_export_to_enc(tag, encoding);
}
+ const char *value_ptr = StringValuePtr(value);
yaml_scalar_event_initialize(
&event,
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
- (yaml_char_t*)StringValuePtr(value),
+ (yaml_char_t*)value_ptr,
(int)RSTRING_LEN(value),
plain ? 1 : 0,
quoted ? 1 : 0,