@@ -1533,12 +1533,18 @@ ThInfo {
15331533set_max_dtoa_threads (unsigned int n )
15341534{
15351535 size_t L ;
1536+ ThInfo * newTI1 ;
15361537
15371538 if (n > maxthreads ) {
15381539 L = n * sizeof (ThInfo );
15391540 if (TI1 ) {
1540- TI1 = (ThInfo * )REALLOC (TI1 , L );
1541- memset (TI1 + maxthreads , 0 , (n - maxthreads )* sizeof (ThInfo ));
1541+ newTI1 = (ThInfo * )REALLOC (TI1 , L );
1542+ if (newTI1 ) {
1543+ TI1 = newTI1 ;
1544+ memset (TI1 + maxthreads , 0 , (n - maxthreads )* sizeof (ThInfo ));
1545+ }
1546+ else
1547+ return ;
15421548 }
15431549 else {
15441550 TI1 = (ThInfo * )MALLOC (L );
@@ -1871,7 +1877,7 @@ mult(Bigint *a, Bigint *b MTd)
18711877#else
18721878#ifdef Pack_32
18731879 for (; xb < xbe ; xb ++ , xc0 ++ ) {
1874- if (y = * xb & 0xffff ) {
1880+ if (( y = * xb & 0xffff ) ) {
18751881 x = xa ;
18761882 xc = xc0 ;
18771883 carry = 0 ;
@@ -1885,7 +1891,7 @@ mult(Bigint *a, Bigint *b MTd)
18851891 while (x < xae );
18861892 * xc = carry ;
18871893 }
1888- if (y = * xb >> 16 ) {
1894+ if (( y = * xb >> 16 ) ) {
18891895 x = xa ;
18901896 xc = xc0 ;
18911897 carry = 0 ;
@@ -2718,13 +2724,14 @@ enum { /* rounding values: same as FLT_ROUNDS */
27182724 };
27192725
27202726 void
2721- gethex ( const char * * sp , U * rvp , int rounding , int sign MTd )
2727+ gethex (const char * * sp , U * rvp , int rounding , int sign MTd )
27222728{
27232729 Bigint * b ;
2730+ char d ;
27242731 const unsigned char * decpt , * s0 , * s , * s1 ;
27252732 Long e , e1 ;
27262733 ULong L , lostbits , * x ;
2727- int big , denorm , esign , havedig , k , n , nbits , up , zret ;
2734+ int big , denorm , esign , havedig , k , n , nb , nbits , nz , up , zret ;
27282735#ifdef IBM
27292736 int j ;
27302737#endif
@@ -2742,6 +2749,9 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
27422749#endif
27432750#endif /*}}*/
27442751 };
2752+ #ifdef IEEE_Arith
2753+ int check_denorm = 0 ;
2754+ #endif
27452755#ifdef USE_LOCALE
27462756 int i ;
27472757#ifdef NO_LOCALE_CACHE
@@ -2893,7 +2903,7 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
28932903 k ++ ;
28942904 b = Balloc (k MTa );
28952905 x = b -> x ;
2896- n = 0 ;
2906+ havedig = n = nz = 0 ;
28972907 L = 0 ;
28982908#ifdef USE_LOCALE
28992909 for (i = 0 ; decimalpoint [i + 1 ]; ++ i );
@@ -2908,22 +2918,28 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
29082918 if (* -- s1 == '.' )
29092919 continue ;
29102920#endif
2921+ if ((d = hexdig [* s1 ]))
2922+ havedig = 1 ;
2923+ else if (!havedig ) {
2924+ e += 4 ;
2925+ continue ;
2926+ }
29112927 if (n == ULbits ) {
29122928 * x ++ = L ;
29132929 L = 0 ;
29142930 n = 0 ;
29152931 }
2916- L |= (hexdig [ * s1 ] & 0x0f ) << n ;
2932+ L |= (d & 0x0f ) << n ;
29172933 n += 4 ;
29182934 }
29192935 * x ++ = L ;
29202936 b -> wds = n = x - b -> x ;
2921- n = ULbits * n - hi0bits (L );
2937+ nb = ULbits * n - hi0bits (L );
29222938 nbits = Nbits ;
29232939 lostbits = 0 ;
29242940 x = b -> x ;
2925- if (n > nbits ) {
2926- n -= nbits ;
2941+ if (nb > nbits ) {
2942+ n = nb - nbits ;
29272943 if (any_on (b ,n )) {
29282944 lostbits = 1 ;
29292945 k = n - 1 ;
@@ -2936,8 +2952,8 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
29362952 rshift (b , n );
29372953 e += n ;
29382954 }
2939- else if (n < nbits ) {
2940- n = nbits - n ;
2955+ else if (nb < nbits ) {
2956+ n = nbits - nb ;
29412957 b = lshift (b , n MTa );
29422958 e -= n ;
29432959 x = b -> x ;
@@ -2992,12 +3008,49 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
29923008 return ;
29933009 }
29943010 k = n - 1 ;
3011+ #ifdef IEEE_Arith
3012+ if (!k ) {
3013+ switch (rounding ) {
3014+ case Round_near :
3015+ if (((b -> x [0 ] & 3 ) == 3 ) || (lostbits && (b -> x [0 ] & 1 ))) {
3016+ multadd (b , 1 , 1 MTa );
3017+ emin_check :
3018+ if (b -> x [1 ] == (1 << (Exp_shift + 1 ))) {
3019+ rshift (b ,1 );
3020+ e = emin ;
3021+ goto normal ;
3022+ }
3023+ }
3024+ break ;
3025+ case Round_up :
3026+ if (!sign && (lostbits || (b -> x [0 ] & 1 ))) {
3027+ incr_denorm :
3028+ multadd (b , 1 , 2 MTa );
3029+ check_denorm = 1 ;
3030+ lostbits = 0 ;
3031+ goto emin_check ;
3032+ }
3033+ break ;
3034+ case Round_down :
3035+ if (sign && (lostbits || (b -> x [0 ] & 1 )))
3036+ goto incr_denorm ;
3037+ break ;
3038+ }
3039+ }
3040+ #endif
29953041 if (lostbits )
29963042 lostbits = 1 ;
29973043 else if (k > 0 )
29983044 lostbits = any_on (b ,k );
3045+ #ifdef IEEE_Arith
3046+ else if (check_denorm )
3047+ goto no_lostbits ;
3048+ #endif
29993049 if (x [k >>kshift ] & 1 << (k & kmask ))
30003050 lostbits |= 2 ;
3051+ #ifdef IEEE_Arith
3052+ no_lostbits :
3053+ #endif
30013054 nbits -= n ;
30023055 rshift (b ,n );
30033056 e = emin ;
@@ -3022,16 +3075,9 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
30223075 k = b -> wds ;
30233076 b = increment (b MTa );
30243077 x = b -> x ;
3025- if (denorm ) {
3026- #if 0
3027- if (nbits == Nbits - 1
3028- && x [nbits >> kshift ] & 1 << (nbits & kmask ))
3029- denorm = 0 ; /* not currently used */
3030- #endif
3031- }
3032- else if (b -> wds > k
3078+ if (!denorm && (b -> wds > k
30333079 || ((n = nbits & kmask ) != 0
3034- && hi0bits (x [k - 1 ]) < 32 - n )) {
3080+ && hi0bits (x [k - 1 ]) < 32 - n ))) {
30353081 rshift (b ,1 );
30363082 if (++ e > Emax )
30373083 goto ovfl ;
@@ -3041,8 +3087,10 @@ gethex( const char **sp, U *rvp, int rounding, int sign MTd)
30413087#ifdef IEEE_Arith
30423088 if (denorm )
30433089 word0 (rvp ) = b -> wds > 1 ? b -> x [1 ] & ~0x100000 : 0 ;
3044- else
3090+ else {
3091+ normal :
30453092 word0 (rvp ) = (b -> x [1 ] & ~0x100000 ) | ((e + 0x3ff + 52 ) << 20 );
3093+ }
30463094 word1 (rvp ) = b -> x [0 ];
30473095#endif
30483096#ifdef IBM
@@ -3409,6 +3457,7 @@ bigcomp(U *rv, const char *s0, BCinfo *bc MTd)
34093457 if ((j = ((word0 (rv ) & Exp_mask ) >> Exp_shift ) - bc -> scale ) <= 0 ) {
34103458 i = 1 - j ;
34113459 if (i <= 31 ) {
3460+ /* cppcheck-suppress integerOverflowCond */
34123461 if (word1 (rv ) & (0x1 << i ))
34133462 goto odd ;
34143463 }
@@ -3619,10 +3668,11 @@ fpconv_strtod(const char *s00, char **se)
36193668 c = * ++ s ;
36203669 if (c > '0' && c <= '9' ) {
36213670 L = c - '0' ;
3622- s1 = s ;
3623- while ((c = * ++ s ) >= '0' && c <= '9' )
3624- L = 10 * L + c - '0' ;
3625- if (s - s1 > 8 || L > 19999 )
3671+ while ((c = * ++ s ) >= '0' && c <= '9' ) {
3672+ if (L <= 19999 )
3673+ L = 10 * L + c - '0' ;
3674+ }
3675+ if (L > 19999 )
36263676 /* Avoid confusion from exponents
36273677 * so large that e might overflow.
36283678 */
@@ -4884,6 +4934,7 @@ nrv_alloc(const char *s, char *s0, size_t s0len, char **rve, int n MTd)
48844934 s0 = rv_alloc (n MTa );
48854935 else if (s0len <= n ) {
48864936 rv = 0 ;
4937+ /* cppcheck-suppress nullPointerArithmetic */
48874938 t = rv + n ;
48884939 goto rve_chk ;
48894940 }
@@ -5237,9 +5288,11 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
52375288#ifndef SET_INEXACT
52385289#ifdef Check_FLT_ROUNDS
52395290 try_quick = Rounding == 1 ;
5291+ #else
5292+ try_quick = 1 ;
52405293#endif
52415294#endif /*SET_INEXACT*/
5242- #endif
5295+ #endif /*USE_BF96*/
52435296
52445297 if (mode > 5 ) {
52455298 mode -= 4 ;
@@ -5281,6 +5334,7 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
52815334 else if (blen <= i ) {
52825335 buf = 0 ;
52835336 if (rve )
5337+ /* cppcheck-suppress nullPointerArithmetic */
52845338 * rve = buf + i ;
52855339 return buf ;
52865340 }
@@ -5469,6 +5523,7 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
54695523 res3 = p10 -> b1 * dbhi + (tv3 & 0xffffffffull );
54705524 res = p10 -> b0 * dbhi + (tv3 >>32 ) + (res3 >>32 );
54715525 be += p10 -> e - 0x3fe ;
5526+ /* cppcheck-suppress integerOverflowCond */
54725527 eulp = j1 = be - 54 + ulpadj ;
54735528 if (!(res & 0x8000000000000000ull )) {
54745529 -- be ;
0 commit comments