Permalink
Browse files

Check json_alloc return value in json_new_value

  • Loading branch information...
1 parent c4778ad commit fb2e321296baf91c32651536663f9e57d331b991 @udp committed Feb 12, 2012
Showing with 15 additions and 6 deletions.
  1. +15 −6 json.c
View
21 json.c
@@ -103,26 +103,35 @@ static int new_value
{
case json_array:
- value->u.array.values = (json_value **) json_alloc
- (state, value->u.array.length * sizeof (json_value *), 0);
+ if (! (value->u.array.values = (json_value **) json_alloc
+ (state, value->u.array.length * sizeof (json_value *), 0)) )
+ {
+ return 0;
+ }
break;
case json_object:
values_size = sizeof (*value->u.object.values) * value->u.object.length;
- (*(void **) &value->u.object.values) = json_alloc
- (state, values_size + ((unsigned long) value->u.object.values), 0);
+ if (! ((*(void **) &value->u.object.values) = json_alloc
+ (state, values_size + ((unsigned long) value->u.object.values), 0)) )
+ {
+ return 0;
+ }
value->_reserved.object_mem = (*(char **) &value->u.object.values) + values_size;
break;
case json_string:
- value->u.string.ptr = (json_char *) json_alloc
- (state, (value->u.string.length + 1) * sizeof (json_char), 0);
+ if (! (value->u.string.ptr = (json_char *) json_alloc
+ (state, (value->u.string.length + 1) * sizeof (json_char), 0)) )
+ {
+ return 0;
+ }
break;
};

0 comments on commit fb2e321

Please sign in to comment.