Skip to content

Commit c3b6326

Browse files
committed
Add more tests for coverage
1 parent a2824b8 commit c3b6326

25 files changed

+97
-31
lines changed

src/yyjson.c

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4659,12 +4659,12 @@ static_inline bool read_num(u8 **ptr, u8 **pre, yyjson_read_flag flg,
46594659
/** Read unicode escape sequence. */
46604660
static_inline bool read_uni_esc(u8 **src_ptr, u8 **dst_ptr, const char **msg) {
46614661
#define return_err(_end, _msg) *msg = _msg; *src_ptr = _end; return false
4662-
4662+
46634663
u8 *src = *src_ptr;
46644664
u8 *dst = *dst_ptr;
46654665
u16 hi, lo;
46664666
u32 uni;
4667-
4667+
46684668
src += 2; /* skip `\u` */
46694669
if (unlikely(!hex_load_4(src, &hi))) {
46704670
return_err(src - 2, "invalid escaped sequence in string");
@@ -6620,9 +6620,6 @@ yyjson_doc *yyjson_incr_read(yyjson_incr_state *state, size_t len,
66206620
if (unlikely(!len)) {
66216621
return_err_inv_param("input length is 0");
66226622
}
6623-
if (unlikely(len < (usize)(state->cur - state->hdr))) {
6624-
return_err_inv_param("length is smaller than parsed length");
6625-
}
66266623
if (unlikely(len > state->buf_len)) {
66276624
return_err_inv_param("length is greater than total input length");
66286625
}
@@ -7247,15 +7244,6 @@ static const u8 dec_trailing_zero_table[] = {
72477244
1, 0, 0, 0, 0, 0, 0, 0, 0, 0
72487245
};
72497246

7250-
static_inline u8 *write_u32_len_1_to_9(u32 val, u8 *buf) {
7251-
if (val >= 100000000) {
7252-
u32 hi = val / 10000000;
7253-
val = val - hi * 10000000;
7254-
*buf++ = (u8)(hi + '0');
7255-
}
7256-
return write_u32_len_1_to_8((u32)val, buf);
7257-
}
7258-
72597247
static_inline u8 *write_u64_len_1_to_16(u64 val, u8 *buf) {
72607248
u64 hgh;
72617249
u32 low;
@@ -7860,7 +7848,7 @@ static_noinline u8 *write_f32_raw(u8 *buf, u64 raw_f64,
78607848
f32_bin_to_dec(sig_raw, exp_raw, sig_bin, exp_bin, &sig_dec, &exp_dec);
78617849

78627850
/* write significand part */
7863-
end = write_u32_len_1_to_9(sig_dec, buf + 1);
7851+
end = write_u32_len_1_to_8(sig_dec, buf + 1);
78647852
buf[0] = buf[1];
78657853
buf[1] = '.';
78667854
exp_dec += (i32)(end - buf) - 2;
@@ -8717,11 +8705,10 @@ static_inline u8 *write_str(u8 *cur, bool esc, bool inv,
87178705
#if YYJSON_DISABLE_UTF8_VALIDATION
87188706
byte_copy_2(cur, src);
87198707
#else
8720-
u32 v4 = 0;
8721-
u16 v2 = byte_load_2(src);
8722-
byte_copy_2(&v4, &v2);
8723-
if (unlikely(!is_utf8_seq2(v4))) goto err_cpy;
8724-
byte_copy_2(cur, src);
8708+
u32 uni = 0;
8709+
byte_copy_2(&uni, src);
8710+
if (unlikely(!is_utf8_seq2(uni))) goto err_cpy;
8711+
byte_copy_2(cur, &uni);
87258712
#endif
87268713
cur += 2;
87278714
src += 2;
@@ -8736,15 +8723,15 @@ static_inline u8 *write_str(u8 *cur, bool esc, bool inv,
87368723
cur[2] = src[2];
87378724
}
87388725
#else
8739-
u32 v, tmp;
8726+
u32 uni, tmp;
87408727
if (likely(src + 4 <= end)) {
8741-
v = byte_load_4(src);
8742-
if (unlikely(!is_utf8_seq3(v))) goto err_cpy;
8728+
uni = byte_load_4(src);
8729+
if (unlikely(!is_utf8_seq3(uni))) goto err_cpy;
87438730
byte_copy_4(cur, src);
87448731
} else {
8745-
v = byte_load_3(src);
8746-
if (unlikely(!is_utf8_seq3(v))) goto err_cpy;
8747-
byte_copy_4(cur, &v);
8732+
uni = byte_load_3(src);
8733+
if (unlikely(!is_utf8_seq3(uni))) goto err_cpy;
8734+
byte_copy_4(cur, &uni);
87488735
}
87498736
#endif
87508737
cur += 3;
@@ -8755,9 +8742,9 @@ static_inline u8 *write_str(u8 *cur, bool esc, bool inv,
87558742
#if YYJSON_DISABLE_UTF8_VALIDATION
87568743
byte_copy_4(cur, src);
87578744
#else
8758-
u32 v, tmp;
8759-
v = byte_load_4(src);
8760-
if (unlikely(!is_utf8_seq4(v))) goto err_cpy;
8745+
u32 uni, tmp;
8746+
uni = byte_load_4(src);
8747+
if (unlikely(!is_utf8_seq4(uni))) goto err_cpy;
87618748
byte_copy_4(cur, src);
87628749
#endif
87638750
cur += 4;
@@ -8837,7 +8824,7 @@ static_inline u8 *write_str(u8 *cur, bool esc, bool inv,
88378824
case CHAR_ENC_ERR_1: {
88388825
goto err_one;
88398826
}
8840-
default: break;
8827+
default: break; /* unreachable */
88418828
}
88428829

88438830
copy_end:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[ 1 , "" , true , { "key" : "val" , "key2" : "val2" } ]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
'abc"
3+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
['abc"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
'abc": 123
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{'abc":123}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"key": 'abc"
3+
}

0 commit comments

Comments
 (0)