| @@ -2240,15 +2240,18 @@ static void parse_string(const char *s, int len) · 2239 unmodified lines |
| 2240 | #endif | 2240 | #endif |
| 2241 | | 2241 | |
| 2242 | /* bn = (bn << shift) | or_val */ | 2242 | /* bn = (bn << shift) | or_val */ |
| 2243 | static void bn_lshift(unsigned int *bn, int shift, int or_val) | 2243 | static int bn_lshift(unsigned int *bn, int shift, int or_val) |
| 2244 | { | 2244 | { |
| 2245 | int i; | 2245 | int i; |
| 2246 | unsigned int v; | 2246 | unsigned int v; |
| | 2247 | if (bn[BN_SIZE - 1] >> (32 - shift)) |
| | 2248 | return shift; |
| 2247 | for(i=0;i<BN_SIZE;i++) { | 2249 | for(i=0;i<BN_SIZE;i++) { |
| 2248 | v = bn[i]; | 2250 | v = bn[i]; |
| 2249 | bn[i] = (v << shift) | or_val; | 2251 | bn[i] = (v << shift) | or_val; |
| 2250 | or_val = v >> (32 - shift); | 2252 | or_val = v >> (32 - shift); |
| 2251 | } | 2253 | } |
| | 2254 | return 0; |
| 2252 | } | 2255 | } |
| 2253 | | 2256 | |
| 2254 | static void bn_zero(unsigned int *bn) | 2257 | static void bn_zero(unsigned int *bn) |
| @@ -2321,6 +2324,7 @@ static void parse_number(const char *p) · 66 unmodified lines |
| 2321 | it by hand */ | 2324 | it by hand */ |
| 2322 | /* hexadecimal or binary floats */ | 2325 | /* hexadecimal or binary floats */ |
| 2323 | /* XXX: handle overflows */ | 2326 | /* XXX: handle overflows */ |
| | 2327 | frac_bits = 0; |
| 2324 | *q = '\0'; | 2328 | *q = '\0'; |
| 2325 | if (b == 16) | 2329 | if (b == 16) |
| 2326 | shift = 4; | 2330 | shift = 4; |
| @@ -2339,9 +2343,8 @@ static void parse_number(const char *p) · 12 unmodified lines |
| 2339 | } else { | 2343 | } else { |
| 2340 | t = t - '0'; | 2344 | t = t - '0'; |
| 2341 | } | 2345 | } |
| 2342 | bn_lshift(bn, shift, t); | 2346 | frac_bits -= bn_lshift(bn, shift, t); |
| 2343 | } | 2347 | } |
| 2344 | frac_bits = 0; | | |
| 2345 | if (ch == '.') { | 2348 | if (ch == '.') { |
| 2346 | ch = *p++; | 2349 | ch = *p++; |
| 2347 | while (1) { | 2350 | while (1) { |
| @@ -2357,7 +2360,7 @@ static void parse_number(const char *p) · 9 unmodified lines |
| 2357 | } | 2360 | } |
| 2358 | if (t >= b) | 2361 | if (t >= b) |
| 2359 | tcc_error("invalid digit"); | 2362 | tcc_error("invalid digit"); |
| 2360 | bn_lshift(bn, shift, t); | 2363 | frac_bits -= bn_lshift(bn, shift, t); |
| 2361 | frac_bits += shift; | 2364 | frac_bits += shift; |
| 2362 | ch = *p++; | 2365 | ch = *p++; |
| 2363 | } | 2366 | } |
| @@ -2376,7 +2379,9 @@ static void parse_number(const char *p) · 12 unmodified lines |
| 2376 | if (ch < '0' || ch > '9') | 2379 | if (ch < '0' || ch > '9') |
| 2377 | expect("exponent digits"); | 2380 | expect("exponent digits"); |
| 2378 | while (ch >= '0' && ch <= '9') { | 2381 | while (ch >= '0' && ch <= '9') { |
| 2379 | exp_val = exp_val * 10 + ch - '0'; | 2382 | /* If exp_val is this large ldexp will return HUGE_VAL */ |
| | 2383 | if (exp_val < 100000000) |
| | 2384 | exp_val = exp_val * 10 + ch - '0'; |
| 2380 | ch = *p++; | 2385 | ch = *p++; |
| 2381 | } | 2386 | } |
| 2382 | exp_val = exp_val * s; | 2387 | exp_val = exp_val * s; |
| @@ -2405,12 +2410,11 @@ static void parse_number(const char *p) · 22 unmodified lines |
| 2405 | #ifdef TCC_USING_DOUBLE_FOR_LDOUBLE | 2410 | #ifdef TCC_USING_DOUBLE_FOR_LDOUBLE |
| 2406 | tokc.d = d; | 2411 | tokc.d = d; |
| 2407 | #else | 2412 | #else |
| 2408 | /* XXX: not large enough */ | 2413 | tokc.ld = d; |
| 2409 | tokc.ld = (long double)d; | | |
| 2410 | #endif | 2414 | #endif |
| 2411 | } else { | 2415 | } else { |
| 2412 | tok = TOK_CDOUBLE; | 2416 | tok = TOK_CDOUBLE; |
| 2413 | tokc.d = d; | 2417 | tokc.d = (double)d; |
| 2414 | } | 2418 | } |
| 2415 | } else { | 2419 | } else { |
| 2416 | /* decimal floats */ | 2420 | /* decimal floats */ |