diff options
author | Philipp Stephani <phst@google.com> | 2017-12-20 18:27:04 +0100 |
---|---|---|
committer | Philipp Stephani <phst@google.com> | 2017-12-20 18:27:04 +0100 |
commit | 45228cada4c379fc1a290b1a0866f51e24396b47 (patch) | |
tree | 412bc473764978723841a320bdb4db2b59688e74 | |
parent | 9e5af7c3b77f81a7d1720073dca600e51fe9962d (diff) | |
download | jansson-45228cada4c379fc1a290b1a0866f51e24396b47.zip jansson-45228cada4c379fc1a290b1a0866f51e24396b47.tar.gz jansson-45228cada4c379fc1a290b1a0866f51e24396b47.tar.bz2 |
Use a more specific error code for premature end of input
-rw-r--r-- | src/load.c | 4 | ||||
-rw-r--r-- | test/suites/api/test_load.c | 8 |
2 files changed, 12 insertions, 0 deletions
@@ -122,6 +122,10 @@ static void error_set(json_error_t *error, const lex_t *lex, } else { + if(code == json_error_invalid_syntax) { + /* More specific error code for premature end of file. */ + code = json_error_premature_end_of_input; + } if(lex->stream.state == STREAM_STATE_ERROR) { /* No context for UTF-8 decoding errors */ result = msg_text; diff --git a/test/suites/api/test_load.c b/test/suites/api/test_load.c index a708de5..a3bdc57 100644 --- a/test/suites/api/test_load.c +++ b/test/suites/api/test_load.c @@ -221,6 +221,14 @@ static void error_code() fail("error.text longer than expected"); if(json_error_code(&error) != json_error_end_of_input_expected) fail("json_loads returned incorrect error code"); + + json = json_loads("{\"foo\": ", 0, &error); + if(json != NULL) + fail("json_loads returned not NULL"); + if(strlen(error.text) >= JSON_ERROR_TEXT_LENGTH) + fail("error.text longer than expected"); + if(json_error_code(&error) != json_error_premature_end_of_input) + fail("json_loads returned incorrect error code"); } static void run_tests() |