cosmopolitan/test/libc
Gabriel Ravier e3d28de8a6
Fix UB in gdtoa hexadecimal float scanf and strtod (#1288)
When reading hexadecimal floats, cosmopolitan would previously sometimes
print a number of warnings relating to undefined behavior on left shift:

third_party/gdtoa/gethex.c:172: ubsan warning: signed left shift changed
sign bit or overflowed 12 'int' 28 'int' is undefined behavior

This is because gdtoa assumes left shifts are safe when overflow happens
even on signed integers - this is false: the C standard considers it UB.
This is easy to fix, by simply casting the shifted value to unsigned, as
doing so does not change the value or the semantics of the left shifting
(except for avoiding the undefined behavior, as the C standard specifies
that unsigned overflow yields wraparound, avoiding undefined behaviour).

This commit does this, and adds a testcase that previously triggered UB.
(this also adds test macros to test for exact float equality, instead of
the existing {EXPECT,ASSERT}_FLOAT_EQ macros which only tests inputs for
being "almost equal" (with a significant epsilon) whereas exact equality
makes more sense for certain things such as reading floats from strings,
and modifies other testcases for sscanf/fscanf of floats to utilize it).
2024-09-14 17:11:04 -07:00
..
calls Rewrite Windows connect() 2024-09-12 23:07:52 -07:00
fmt Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
intrin Fix occasional crash in test/libc/intrin/mmap_test (#1289) 2024-09-14 17:07:56 -07:00
log Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
mem Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
nexgen32e Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
proc Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
runtime Make realloc() go 100x faster on Linux/NetBSD 2024-07-07 12:40:30 -07:00
sock Rewrite Windows connect() 2024-09-12 23:07:52 -07:00
stdio Fix UB in gdtoa hexadecimal float scanf and strtod (#1288) 2024-09-14 17:11:04 -07:00
str Add more tests for strlcpy() 2024-09-13 01:14:35 -07:00
thread Make recursive mutexes faster 2024-09-10 00:08:59 -07:00
time Update Musl Libc code 2024-07-30 22:51:29 -07:00
tinymath Release Cosmopolitan v3.8.0 2024-08-30 20:14:07 -07:00
x Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
xed Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
BUILD.mk Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00