Skip to content

Commit

Permalink
Fix emitter states handling when write_indicator fails
Browse files Browse the repository at this point in the history
There are cases where yaml_emitter_write_indicator fails.
In that case POP is called on emitter->indents but not on emitter->states,
which results in a leftover event in the stack, and later POP is called
on an empty emitter->indents stack.

This commit does not fix the case of the failing yaml_emitter_write_indicator.
This is still investigated.
  • Loading branch information
perlpunk committed Apr 9, 2024
1 parent 1e66c1e commit ff577b9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ yaml_emitter_emit_flow_sequence_item(yaml_emitter_t *emitter,
{
emitter->flow_level --;
emitter->indent = POP(emitter, emitter->indents);
emitter->state = POP(emitter, emitter->states);
if (emitter->canonical && !first) {
if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0))
return 0;
Expand All @@ -767,7 +768,6 @@ yaml_emitter_emit_flow_sequence_item(yaml_emitter_t *emitter,
}
if (!yaml_emitter_write_indicator(emitter, "]", 0, 0, 0))
return 0;
emitter->state = POP(emitter, emitter->states);

return 1;
}
Expand Down Expand Up @@ -808,6 +808,7 @@ yaml_emitter_emit_flow_mapping_key(yaml_emitter_t *emitter,
{
emitter->flow_level --;
emitter->indent = POP(emitter, emitter->indents);
emitter->state = POP(emitter, emitter->states);
if (emitter->canonical && !first) {
if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0))
return 0;
Expand All @@ -816,7 +817,6 @@ yaml_emitter_emit_flow_mapping_key(yaml_emitter_t *emitter,
}
if (!yaml_emitter_write_indicator(emitter, "}", 0, 0, 0))
return 0;
emitter->state = POP(emitter, emitter->states);

return 1;
}
Expand Down

0 comments on commit ff577b9

Please sign in to comment.