diff --git a/src/yajl_gen.c b/src/yajl_gen.c index 582fdff..1c8dd0f 100644 --- a/src/yajl_gen.c +++ b/src/yajl_gen.c @@ -149,9 +149,6 @@ yajl_gen_alloc(const yajl_alloc_funcs *afs) } g = (yajl_gen) YA_MALLOC(afs, sizeof(struct yajl_gen_t)); - if (!g) { - return NULL; - } memset((void *) g, 0, sizeof(struct yajl_gen_t)); /* copy in pointers to allocation routines */ g->alloc = *afs; diff --git a/src/yajl_parser.c b/src/yajl_parser.c index 90c93cf..af02399 100644 --- a/src/yajl_parser.c +++ b/src/yajl_parser.c @@ -91,7 +91,6 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, memneeded += strlen(errorText); } str = (unsigned char *) YA_MALLOC(&(hand->alloc), memneeded + 2); - if (!str) return NULL; str[0] = 0; strcat((char *) str, errorType); strcat((char *) str, " error"); @@ -131,12 +130,10 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, YA_MALLOC(&(hand->alloc), (size_t)(strlen((char *) str) + strlen((char *) text) + strlen(arrow) + 1)); - if (newStr) { - newStr[0] = 0; - strcat((char *) newStr, (char *) str); - strcat((char *) newStr, (char *) text); - strcat((char *) newStr, arrow); - } + newStr[0] = 0; + strcat((char *) newStr, (char *) str); + strcat((char *) newStr, (char *) text); + strcat((char *) newStr, arrow); YA_FREE(&(hand->alloc), str); str = (unsigned char *) newStr; } diff --git a/src/yajl_tree.c b/src/yajl_tree.c index 5672752..3b3248b 100644 --- a/src/yajl_tree.c +++ b/src/yajl_tree.c @@ -78,8 +78,7 @@ static yajl_val value_alloc (yajl_type type) yajl_val v; v = YA_MALLOC(yajl_tree_parse_afs, sizeof(*v)); - if (v == NULL) return (NULL); - memset (v, 0, sizeof (*v)); + memset(v, 0, sizeof (*v)); v->type = type; return (v); @@ -138,14 +137,13 @@ static int context_push(context_t *ctx, yajl_val v) { stack_elem_t *stack; + assert(v); + stack = YA_MALLOC(yajl_tree_parse_afs, sizeof(*stack)); - if (stack == NULL) - RETURN_ERROR (ctx, ENOMEM, "Out of memory"); - memset (stack, 0, sizeof (*stack)); + memset(stack, 0, sizeof (*stack)); - assert ((ctx->stack == NULL) - || YAJL_IS_OBJECT (v) - || YAJL_IS_ARRAY (v)); + assert(YAJL_IS_OBJECT (v) || + YAJL_IS_ARRAY (v)); stack->value = v; stack->next = ctx->stack; @@ -194,15 +192,11 @@ static int object_add_keyval(context_t *ctx, tmpk = YA_REALLOC(yajl_tree_parse_afs, (void *) obj->u.object.keys, sizeof(*(obj->u.object.keys)) * (obj->u.object.len + 1)); - if (tmpk == NULL) - RETURN_ERROR(ctx, ENOMEM, "Out of memory"); obj->u.object.keys = tmpk; tmpv = YA_REALLOC(yajl_tree_parse_afs, obj->u.object.values, sizeof (*obj->u.object.values) * (obj->u.object.len + 1)); - if (tmpv == NULL) - RETURN_ERROR(ctx, ENOMEM, "Out of memory"); obj->u.object.values = tmpv; obj->u.object.keys[obj->u.object.len] = key; @@ -229,8 +223,6 @@ static int array_add_value (context_t *ctx, tmp = YA_REALLOC(yajl_tree_parse_afs, array->u.array.values, sizeof(*(array->u.array.values)) * (array->u.array.len + 1)); - if (tmp == NULL) - RETURN_ERROR(ctx, ENOMEM, "Out of memory"); array->u.array.values = tmp; array->u.array.values[array->u.array.len] = value; array->u.array.len++; @@ -306,15 +298,7 @@ static int handle_string (void *ctx, yajl_val v; v = value_alloc (yajl_t_string); - if (v == NULL) - RETURN_ERROR ((context_t *) ctx, STATUS_ABORT, "Out of memory"); - v->u.string = YA_MALLOC(yajl_tree_parse_afs, string_length + 1); - if (v->u.string == NULL) - { - YA_FREE(yajl_tree_parse_afs, v); - RETURN_ERROR ((context_t *) ctx, STATUS_ABORT, "Out of memory"); - } memcpy(v->u.string, string, string_length); v->u.string[string_length] = 0; @@ -327,14 +311,7 @@ static int handle_number (void *ctx, const char *string, size_t string_length) char *endptr; v = value_alloc(yajl_t_number); - if (v == NULL) { - RETURN_ERROR((context_t *) ctx, STATUS_ABORT, "Out of memory"); - } v->u.number.r = YA_MALLOC(yajl_tree_parse_afs, string_length + 1); - if (v->u.number.r == NULL) { - YA_FREE(yajl_tree_parse_afs, v); - RETURN_ERROR((context_t *) ctx, STATUS_ABORT, "Out of memory"); - } memcpy(v->u.number.r, string, string_length); v->u.number.r[string_length] = 0; @@ -360,9 +337,6 @@ static int handle_start_map (void *ctx) yajl_val v; v = value_alloc(yajl_t_object); - if (v == NULL) - RETURN_ERROR ((context_t *) ctx, STATUS_ABORT, "Out of memory"); - v->u.object.keys = NULL; v->u.object.values = NULL; v->u.object.len = 0; @@ -386,9 +360,6 @@ static int handle_start_array (void *ctx) yajl_val v; v = value_alloc(yajl_t_array); - if (v == NULL) - RETURN_ERROR ((context_t *) ctx, STATUS_ABORT, "Out of memory"); - v->u.array.values = NULL; v->u.array.len = 0; @@ -411,9 +382,6 @@ static int handle_boolean (void *ctx, int boolean_value) yajl_val v; v = value_alloc (boolean_value ? yajl_t_true : yajl_t_false); - if (v == NULL) - RETURN_ERROR ((context_t *) ctx, STATUS_ABORT, "Out of memory"); - return ((context_add_value (ctx, v) == 0) ? STATUS_CONTINUE : STATUS_ABORT); } @@ -422,9 +390,6 @@ static int handle_null (void *ctx) yajl_val v; v = value_alloc (yajl_t_null); - if (v == NULL) - RETURN_ERROR ((context_t *) ctx, STATUS_ABORT, "Out of memory"); - return ((context_add_value (ctx, v) == 0) ? STATUS_CONTINUE : STATUS_ABORT); }