Skip to content

Commit

Permalink
Return an error through yajl_gen_get_buf
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Apr 4, 2022
1 parent a4a371f commit e001a1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ext/yajl/api/yajl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ extern "C" {
# endif
#endif

#if defined(__GNUC__)
#define YAJL_WARN_UNUSED __attribute__ ((warn_unused_result))
#else
#define YAJL_WARN_UNUSED
#endif

/** pointer to a malloc function, supporting client overriding memory
* allocation routines */
typedef void * (*yajl_malloc_func)(void *ctx, unsigned int sz);
Expand Down
6 changes: 4 additions & 2 deletions ext/yajl/api/yajl_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ extern "C" {
* buffer to get from */
yajl_gen_no_buf,
/** Tried to decrement at depth 0 */
yajl_depth_underflow
yajl_depth_underflow,
/** Allocation error */
yajl_gen_alloc_error
} yajl_gen_status;

/** an opaque handle to a generator */
Expand Down Expand Up @@ -148,7 +150,7 @@ extern "C" {
/** access the null terminated generator buffer. If incrementally
* outputing JSON, one should call yajl_gen_clear to clear the
* buffer. This allows stream generation. */
YAJL_API yajl_gen_status yajl_gen_get_buf(yajl_gen hand,
YAJL_API YAJL_WARN_UNUSED yajl_gen_status yajl_gen_get_buf(yajl_gen hand,
const unsigned char ** buf,
unsigned int * len);

Expand Down
4 changes: 4 additions & 0 deletions ext/yajl/yajl_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ yajl_gen_get_buf(yajl_gen g, const unsigned char ** buf,
unsigned int * len)
{
if (g->print != (yajl_print_t)&yajl_buf_append) return yajl_gen_no_buf;
yajl_buf_state buf_err = yajl_buf_err((yajl_buf)g->ctx);
if (buf_err) {
return yajl_gen_alloc_error;
}
*buf = yajl_buf_data((yajl_buf)g->ctx);
*len = yajl_buf_len((yajl_buf)g->ctx);
return yajl_gen_status_ok;
Expand Down

0 comments on commit e001a1c

Please sign in to comment.