json BUGFIX in ::lyjson_number_is_zero()
diff --git a/src/json.c b/src/json.c
index 6ae4484..3e36b0f 100644
--- a/src/json.c
+++ b/src/json.c
@@ -355,8 +355,6 @@
/**
* @brief Check if the number can be shortened to zero.
*
- * The input number must be syntactically valid.
- *
* @param[in] in Start of input string;
* @param[in] end End of input string;
* @return 1 if number is zero, otherwise 0.
@@ -364,13 +362,17 @@
static ly_bool
lyjson_number_is_zero(const char *in, const char *end)
{
- assert(end >= in);
+ assert(in < end);
if ((in[0] == '-') || (in[0] == '+')) {
in++;
+ assert(in < end);
}
if ((in[0] == '0') && (in[1] == '.')) {
in += 2;
+ if (!(in < end)) {
+ return 1;
+ }
}
return lyjson_count_in_row(in, end, '0', 0) == end - in;
diff --git a/tests/utests/basic/test_json.c b/tests/utests/basic/test_json.c
index cabafaa..b2cfafd 100644
--- a/tests/utests/basic/test_json.c
+++ b/tests/utests/basic/test_json.c
@@ -505,6 +505,11 @@
assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
CHECK_LOG_CTX("Exponent out-of-bounds in a JSON Number value (1e9999999999999999999).", "Line number 1.");
+ str = "-2.1e0.";
+ assert_non_null(ly_in_memory(in, str));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ CHECK_LOG_CTX("Unexpected character \".\" after JSON number.", "Line number 1.");
+
ly_in_free(in, 0);
}