yajl: Out-of-memory handling; another size_t

This commit is contained in:
Andrew Johnson
2017-06-24 01:20:39 -05:00
parent 4c6b570a46
commit 08ad4de161
5 changed files with 16 additions and 2 deletions

View File

@@ -63,6 +63,9 @@ yajl_alloc(const yajl_callbacks * callbacks,
}
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));
@@ -127,6 +130,9 @@ yajl_parse(yajl_handle hand, const unsigned char * jsonText,
hand->flags & yajl_allow_comments,
!(hand->flags & yajl_dont_validate_strings));
}
if (hand->lexer == NULL) {
return yajl_status_error;
}
status = yajl_do_parse(hand, jsonText, jsonTextLen);
return status;

View File

@@ -57,6 +57,10 @@ void yajl_buf_ensure_available(yajl_buf buf, size_t want)
yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc)
{
yajl_buf b = YA_MALLOC(alloc, sizeof(struct yajl_buf_t));
if (b == NULL) {
return NULL;
}
memset((void *) b, 0, sizeof(struct yajl_buf_t));
b->alloc = alloc;
return b;

View File

@@ -106,6 +106,10 @@ yajl_lex_alloc(yajl_alloc_funcs * alloc,
unsigned int allowComments, unsigned int validateUTF8)
{
yajl_lexer lxr = (yajl_lexer) YA_MALLOC(alloc, sizeof(struct yajl_lexer_t));
if (lxr == NULL) {
return NULL;
}
memset((void *) lxr, 0, sizeof(struct yajl_lexer_t));
lxr->buf = yajl_buf_alloc(alloc);
lxr->allowComments = allowComments;

View File

@@ -34,7 +34,7 @@
/* same semantics as strtol */
long long
yajl_parse_integer(const unsigned char *number, unsigned int length)
yajl_parse_integer(const unsigned char *number, size_t length)
{
long long ret = 0;
long sign = 1;

View File

@@ -72,7 +72,7 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
/* A little built in integer parsing routine with the same semantics as strtol
* that's unaffected by LOCALE. */
long long
yajl_parse_integer(const unsigned char *number, unsigned int length);
yajl_parse_integer(const unsigned char *number, size_t length);
#endif