ext/yajl/yajl.c in yajl-ruby-1.4.1 vs ext/yajl/yajl.c in yajl-ruby-1.4.2
- old
+ new
@@ -54,10 +54,13 @@
statStr = "eof was met before the parse could complete";
break;
case yajl_status_error:
statStr = "parse error";
break;
+ case yajl_status_alloc_failed:
+ statStr = "allocation failed";
+ break;
}
return statStr;
}
yajl_handle
@@ -81,10 +84,12 @@
yajl_set_default_alloc_funcs(&afsBuffer);
afs = &afsBuffer;
}
hand = (yajl_handle) YA_MALLOC(afs, sizeof(struct yajl_handle_t));
+ if (hand == NULL)
+ return NULL;
/* copy in pointers to allocation routines */
memcpy((void *) &(hand->alloc), (void *) afs, sizeof(yajl_alloc_funcs));
if (config != NULL) {
@@ -93,45 +98,55 @@
}
hand->callbacks = callbacks;
hand->ctx = ctx;
hand->lexer = yajl_lex_alloc(&(hand->alloc), allowComments, validateUTF8);
+ if (!hand->lexer) {
+ YA_FREE(afs, hand);
+ return NULL;
+ }
hand->bytesConsumed = 0;
hand->decodeBuf = yajl_buf_alloc(&(hand->alloc));
yajl_bs_init(hand->stateStack, &(hand->alloc));
- yajl_bs_push(hand->stateStack, yajl_state_start);
+ if (yajl_bs_push(hand->stateStack, yajl_state_start)) {
+ return NULL;
+ }
return hand;
}
void
yajl_reset_parser(yajl_handle hand) {
+ assert(hand);
hand->lexer = yajl_lex_realloc(hand->lexer);
}
void
yajl_free(yajl_handle handle)
{
+ assert(handle);
yajl_bs_free(handle->stateStack);
yajl_buf_free(handle->decodeBuf);
yajl_lex_free(handle->lexer);
YA_FREE(&(handle->alloc), handle);
}
yajl_status
yajl_parse(yajl_handle hand, const unsigned char * jsonText,
unsigned int jsonTextLen)
{
+ assert(hand);
yajl_status status;
status = yajl_do_parse(hand, jsonText, jsonTextLen);
return status;
}
yajl_status
yajl_parse_complete(yajl_handle hand)
{
+ assert(hand);
/* The particular case we want to handle is a trailing number.
* Further input consisting of digits could cause our interpretation
* of the number to change (buffered "1" but "2" comes in).
* A very simple approach to this is to inject whitespace to terminate
* any number in the lex buffer.
@@ -141,9 +156,10 @@
unsigned char *
yajl_get_error(yajl_handle hand, int verbose,
const unsigned char * jsonText, unsigned int jsonTextLen)
{
+ assert(hand);
return yajl_render_error_string(hand, jsonText, jsonTextLen, verbose);
}
unsigned int
yajl_get_bytes_consumed(yajl_handle hand)