Commit f80519a
committed
Fix UB in macro.c and streval.c
Clang with UBSan on macOS found these instances of undefined
behaviour. These two files both contain the test
(Sflong_t)d!=d
to check if the value of a long double (Sfdouble_t) 'd' can be
represented in a variable of type long long (Sflong_t).
This test has undefined behaviour if isinf(d), if isnan(d), or if
the value of d is smaller or greater than the minimum or maximum
value that can be stored in an Sflong_t variable.
So this commit adds tests for those conditions. The original test,
(Sflong_t)d!=d, should now only be used to figure out if there is a
decimal fraction, which should be well-defined behaviour.
Note that LDBL_LLONG_MIN and LDBL_LLONG_MAX are defined in
streval.h; they are LLONG_MIN and LLONG_MAX typecast to Sfdouble_t.1 parent c3fa4ef commit f80519a
2 files changed
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2277 | 2277 | | |
2278 | 2278 | | |
2279 | 2279 | | |
2280 | | - | |
| 2280 | + | |
| 2281 | + | |
2281 | 2282 | | |
2282 | 2283 | | |
2283 | 2284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
| 243 | + | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
| 254 | + | |
254 | 255 | | |
255 | 256 | | |
256 | 257 | | |
| |||
0 commit comments