Merge pull request #445 from coreyfarrell/fix-444
Remove inappropriate jsonp_free which caused segmentation fault.
This commit is contained in:
commit
4ba5c7cc5d
@ -359,9 +359,7 @@ static json_t *pack_string(scanner_t *s, va_list *ap)
|
|||||||
return t == '?' && !s->has_error ? json_null() : NULL;
|
return t == '?' && !s->has_error ? json_null() : NULL;
|
||||||
|
|
||||||
if (s->has_error) {
|
if (s->has_error) {
|
||||||
if (!ours)
|
/* It's impossible to reach this point if ours != 0, do not free str. */
|
||||||
jsonp_free(str);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -853,6 +851,7 @@ json_t *json_vpack_ex(json_error_t *error, size_t flags,
|
|||||||
value = pack(&s, &ap_copy);
|
value = pack(&s, &ap_copy);
|
||||||
va_end(ap_copy);
|
va_end(ap_copy);
|
||||||
|
|
||||||
|
/* This will cover all situations where s.has_error is true */
|
||||||
if(!value)
|
if(!value)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -862,10 +861,6 @@ json_t *json_vpack_ex(json_error_t *error, size_t flags,
|
|||||||
set_error(&s, "<format>", json_error_invalid_format, "Garbage after format string");
|
set_error(&s, "<format>", json_error_invalid_format, "Garbage after format string");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(s.has_error) {
|
|
||||||
json_decref(value);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -428,6 +428,11 @@ static void run_tests()
|
|||||||
fail("json_pack failed to a lone +");
|
fail("json_pack failed to a lone +");
|
||||||
check_error(json_error_invalid_format, "Unexpected format character '+'", "<format>", 1, 1, 1);
|
check_error(json_error_invalid_format, "Unexpected format character '+'", "<format>", 1, 1, 1);
|
||||||
|
|
||||||
|
/* Empty format */
|
||||||
|
if(json_pack_ex(&error, 0, ""))
|
||||||
|
fail("json_pack failed to catch empty format string");
|
||||||
|
check_error(json_error_invalid_argument, "NULL or empty format string", "<format>", -1, -1, 0);
|
||||||
|
|
||||||
/* NULL format */
|
/* NULL format */
|
||||||
if(json_pack_ex(&error, 0, NULL))
|
if(json_pack_ex(&error, 0, NULL))
|
||||||
fail("json_pack failed to catch NULL format string");
|
fail("json_pack failed to catch NULL format string");
|
||||||
@ -494,4 +499,20 @@ static void run_tests()
|
|||||||
if(json_pack_ex(&error, 0, "{s:O}", "foo", NULL))
|
if(json_pack_ex(&error, 0, "{s:O}", "foo", NULL))
|
||||||
fail("json_pack failed to catch nullable incref object");
|
fail("json_pack failed to catch nullable incref object");
|
||||||
check_error(json_error_null_value, "NULL object", "<args>", 1, 4, 4);
|
check_error(json_error_null_value, "NULL object", "<args>", 1, 4, 4);
|
||||||
|
|
||||||
|
if(json_pack_ex(&error, 0, "{s+:o}", "foo", "bar", NULL))
|
||||||
|
fail("json_pack failed to catch non-nullable object value");
|
||||||
|
check_error(json_error_null_value, "NULL object", "<args>", 1, 5, 5);
|
||||||
|
|
||||||
|
if(json_pack_ex(&error, 0, "[1s", "Hi"))
|
||||||
|
fail("json_pack failed to catch invalid format");
|
||||||
|
check_error(json_error_invalid_format, "Unexpected format character '1'", "<format>", 1, 2, 2);
|
||||||
|
|
||||||
|
if(json_pack_ex(&error, 0, "[1s+", "Hi", "ya"))
|
||||||
|
fail("json_pack failed to catch invalid format");
|
||||||
|
check_error(json_error_invalid_format, "Unexpected format character '1'", "<format>", 1, 2, 2);
|
||||||
|
|
||||||
|
if(json_pack_ex(&error, 0, "[so]", NULL, json_object()))
|
||||||
|
fail("json_pack failed to catch NULL value");
|
||||||
|
check_error(json_error_null_value, "NULL string", "<args>", 1, 2, 2);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user