@@ -907,7 +907,7 @@ static_inline void u128_mul_add(u64 a, u64 b, u64 c, u64 *hi, u64 *lo) {
907907 u64 h , l , t ;
908908 u128_mul (a , b , & h , & l );
909909 t = l + c ;
910- h += (( t < l ) | (t < c ));
910+ h += (u64 )((( t < l ) | (t < c ) ));
911911 * hi = h ;
912912 * lo = t ;
913913#endif
@@ -1558,11 +1558,11 @@ static_inline void *pointer_read_arr(const char **ptr,
15581558 cur ++ ;
15591559 idx = idx * 10 + add ;
15601560 }
1561- if (cur == hdr ) return NULL ;
1561+ if (cur == hdr || idx >= ( u64 ) USIZE_MAX ) return NULL ;
15621562 * ptr = cur ;
15631563 return mut
1564- ? (void * )yyjson_mut_arr_get (m_arr , idx )
1565- : (void * )yyjson_arr_get (i_arr , idx );
1564+ ? (void * )yyjson_mut_arr_get (m_arr , ( usize ) idx )
1565+ : (void * )yyjson_arr_get (i_arr , ( usize ) idx );
15661566}
15671567
15681568/**
@@ -3402,23 +3402,16 @@ static_inline bool read_number(u8 **ptr,
34023402
34033403 /*
34043404 Read integral part, same as the following code.
3405- For more explanation, see the comments under label `skip_ascii_begin`.
34063405
34073406 for (int i = 1; i <= 18; i++) {
34083407 num = cur[i] - '0';
34093408 if (num <= 9) sig = num + sig * 10;
34103409 else goto digi_sepr_i;
34113410 }
34123411 */
3413- #if YYJSON_IS_REAL_GCC
3414- #define expr_intg (i ) \
3415- if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \
3416- else { __asm volatile("":"=m"(cur[i])::); goto digi_sepr_##i; }
3417- #else
34183412#define expr_intg (i ) \
34193413 if (likely((num = (u64)(cur[i] - (u8)'0')) <= 9)) sig = num + sig * 10; \
34203414 else { goto digi_sepr_##i; }
3421- #endif
34223415 repeat_in_1_18 (expr_intg );
34233416#undef expr_intg
34243417
@@ -3446,19 +3439,11 @@ static_inline bool read_number(u8 **ptr,
34463439
34473440
34483441 /* read fraction part */
3449- #if YYJSON_IS_REAL_GCC
3450- #define expr_frac (i ) \
3451- digi_frac_##i: \
3452- if (likely((num = (u64)(cur[i + 1] - (u8)'0')) <= 9)) \
3453- sig = num + sig * 10; \
3454- else { __asm volatile("":"=m"(cur[i + 1])::); goto digi_stop_##i; }
3455- #else
34563442#define expr_frac (i ) \
34573443 digi_frac_##i: \
34583444 if (likely((num = (u64)(cur[i + 1] - (u8)'0')) <= 9)) \
34593445 sig = num + sig * 10; \
34603446 else { goto digi_stop_##i; }
3461- #endif
34623447 repeat_in_1_18 (expr_frac )
34633448#undef expr_frac
34643449
@@ -6020,8 +6005,8 @@ static_inline u64 round_to_odd(u64 hi, u64 lo, u64 cp) {
60206005 The output significand is shortest decimal but may have trailing zeros.
60216006
60226007 This function use the Schubfach algorithm:
6023- Raffaello Giulietti, The Schubfach way to render doubles (4th version), 2021 .
6024- https://drive.google.com/file/d/1IEeATSVnEE6TkrHlCYNY2GjaraBjOT4f
6008+ Raffaello Giulietti, The Schubfach way to render doubles (5th version), 2022 .
6009+ https://drive.google.com/file/d/1gp5xv4CAa78SVgCeWfGqqI4FfYYYuNFb
60256010 https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-November/083536.html
60266011 https://github.com/openjdk/jdk/pull/3402 (Java implementation)
60276012 https://github.com/abolz/Drachennest (C++ implementation)
@@ -6211,6 +6196,7 @@ static_noinline u8 *write_f64_raw(u8 *buf, u64 raw, yyjson_write_flag flg) {
62116196 /* write with scientific notation */
62126197 /* such as 1.234e56 */
62136198 u8 * end = write_u64_len_15_to_17_trim (buf + 1 , sig_dec );
6199+ end -= (end == buf + 2 ); /* remove '.0', e.g. 2.0e34 -> 2e134 */
62146200 exp_dec += sig_len - 1 ;
62156201 hdr [0 ] = hdr [1 ];
62166202 hdr [1 ] = '.' ;
@@ -7306,8 +7292,8 @@ static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
73067292val_begin :
73077293 val_type = unsafe_yyjson_get_type (val );
73087294 if (val_type == YYJSON_TYPE_STR ) {
7309- is_key = ((u8 )ctn_obj & (u8 )~ctn_len );
7310- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7295+ is_key = (bool )( (u8 )ctn_obj & (u8 )~ctn_len );
7296+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
73117297 str_len = unsafe_yyjson_get_len (val );
73127298 str_ptr = (const u8 * )unsafe_yyjson_get_str (val );
73137299 check_str_len (str_len );
@@ -7320,7 +7306,7 @@ static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
73207306 goto val_end ;
73217307 }
73227308 if (val_type == YYJSON_TYPE_NUM ) {
7323- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7309+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
73247310 incr_len (32 + (no_indent ? 0 : level * 4 ));
73257311 cur = write_indent (cur , no_indent ? 0 : level );
73267312 cur = write_number (cur , val , flg );
@@ -7331,7 +7317,7 @@ static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
73317317 }
73327318 if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ )) ==
73337319 (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ )) {
7334- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7320+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
73357321 ctn_len_tmp = unsafe_yyjson_get_len (val );
73367322 ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ );
73377323 if (unlikely (ctn_len_tmp == 0 )) {
@@ -7358,15 +7344,15 @@ static_inline u8 *yyjson_write_pretty(const yyjson_val *root,
73587344 }
73597345 }
73607346 if (val_type == YYJSON_TYPE_BOOL ) {
7361- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7347+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
73627348 incr_len (16 + (no_indent ? 0 : level * 4 ));
73637349 cur = write_indent (cur , no_indent ? 0 : level );
73647350 cur = write_bool (cur , unsafe_yyjson_get_bool (val ));
73657351 cur += 2 ;
73667352 goto val_end ;
73677353 }
73687354 if (val_type == YYJSON_TYPE_NULL ) {
7369- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7355+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
73707356 incr_len (16 + (no_indent ? 0 : level * 4 ));
73717357 cur = write_indent (cur , no_indent ? 0 : level );
73727358 cur = write_null (cur );
@@ -7794,8 +7780,8 @@ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
77947780val_begin :
77957781 val_type = unsafe_yyjson_get_type (val );
77967782 if (val_type == YYJSON_TYPE_STR ) {
7797- is_key = ((u8 )ctn_obj & (u8 )~ctn_len );
7798- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7783+ is_key = (bool )( (u8 )ctn_obj & (u8 )~ctn_len );
7784+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
77997785 str_len = unsafe_yyjson_get_len (val );
78007786 str_ptr = (const u8 * )unsafe_yyjson_get_str (val );
78017787 check_str_len (str_len );
@@ -7808,7 +7794,7 @@ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
78087794 goto val_end ;
78097795 }
78107796 if (val_type == YYJSON_TYPE_NUM ) {
7811- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7797+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
78127798 incr_len (32 + (no_indent ? 0 : level * 4 ));
78137799 cur = write_indent (cur , no_indent ? 0 : level );
78147800 cur = write_number (cur , (yyjson_val * )val , flg );
@@ -7819,7 +7805,7 @@ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
78197805 }
78207806 if ((val_type & (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ )) ==
78217807 (YYJSON_TYPE_ARR & YYJSON_TYPE_OBJ )) {
7822- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7808+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
78237809 ctn_len_tmp = unsafe_yyjson_get_len (val );
78247810 ctn_obj_tmp = (val_type == YYJSON_TYPE_OBJ );
78257811 if (unlikely (ctn_len_tmp == 0 )) {
@@ -7848,15 +7834,15 @@ static_inline u8 *yyjson_mut_write_pretty(const yyjson_mut_val *root,
78487834 }
78497835 }
78507836 if (val_type == YYJSON_TYPE_BOOL ) {
7851- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7837+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
78527838 incr_len (16 + (no_indent ? 0 : level * 4 ));
78537839 cur = write_indent (cur , no_indent ? 0 : level );
78547840 cur = write_bool (cur , unsafe_yyjson_get_bool (val ));
78557841 cur += 2 ;
78567842 goto val_end ;
78577843 }
78587844 if (val_type == YYJSON_TYPE_NULL ) {
7859- no_indent = ((u8 )ctn_obj & (u8 )ctn_len );
7845+ no_indent = (bool )( (u8 )ctn_obj & (u8 )ctn_len );
78607846 incr_len (16 + (no_indent ? 0 : level * 4 ));
78617847 cur = write_indent (cur , no_indent ? 0 : level );
78627848 cur = write_null (cur );
0 commit comments