Skip to content

Commit

Permalink
Disallow misuse of ucl_object_emit_streamline_start_container
Browse files Browse the repository at this point in the history
Issue: #300
Closes: #300
  • Loading branch information
vstakhov committed Apr 24, 2024
1 parent f897d5a commit 37edb29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/ucl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ UCL_EXTERN struct ucl_emitter_context* ucl_object_emit_streamline_new (
* @param ctx streamlined context
* @param obj container object
*/
UCL_EXTERN void ucl_object_emit_streamline_start_container (
UCL_EXTERN bool ucl_object_emit_streamline_start_container (
struct ucl_emitter_context *ctx, const ucl_object_t *obj);
/**
* Add a complete UCL object to streamlined output
Expand Down
12 changes: 10 additions & 2 deletions src/ucl_emitter_streamline.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ucl_object_emit_streamline_new (const ucl_object_t *obj,
return (struct ucl_emitter_context *)sctx;
}

void
bool
ucl_object_emit_streamline_start_container (struct ucl_emitter_context *ctx,
const ucl_object_t *obj)
{
Expand All @@ -113,12 +113,20 @@ ucl_object_emit_streamline_start_container (struct ucl_emitter_context *ctx,
st->is_array = true;
sctx->ops->ucl_emitter_start_array (ctx, obj, top == NULL, print_key);
}
else {
else if (obj != NULL && obj->type == UCL_OBJECT) {
st->is_array = false;
sctx->ops->ucl_emitter_start_object (ctx, obj, top == NULL, print_key);
}
else {
/* API MISUSE */
free (st);

return false;
}
LL_PREPEND (sctx->containers, st);
}

return true;
}

void
Expand Down

0 comments on commit 37edb29

Please sign in to comment.