Commit 1acaeae
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 dd1efb4 commit 1acaeae
2 files changed
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2210 | 2210 | | |
2211 | 2211 | | |
2212 | 2212 | | |
2213 | | - | |
| 2213 | + | |
| 2214 | + | |
2214 | 2215 | | |
2215 | 2216 | | |
2216 | 2217 | | |
| |||
| 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