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