cosmopolitan/libc/testlib
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
..
almostequal.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
almostequalf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
almostequallongdouble.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
aspect.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
bench.h Reduce header complexity 2023-11-28 14:39:42 -08:00
bench.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
benchmark.h Add more tests for strlcpy() 2024-09-13 01:14:35 -07:00
benchrunner.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
binequals.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
blake2b256_tests.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
blake2b256_tests.txt Run all BLAKE2B256 test vectors (#1185) 2024-05-24 10:59:23 -07:00
blocktronics.h Reduce header complexity 2023-11-28 14:39:42 -08:00
blocktronics.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
blocktronics.txt Remove trailing whitespace from all files (#497) 2022-07-20 20:31:16 -07:00
BUILD.mk Fix UB in gdtoa hexadecimal float scanf and strtod (#1288) 2024-09-14 17:11:04 -07:00
clearxmmregisters.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
contains.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
endswith.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
exactlyequallongdouble.c Fix UB in gdtoa hexadecimal float scanf and strtod (#1288) 2024-09-14 17:11:04 -07:00
extract.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ezbench.h Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
ezbenchcontrol.c Make improvements 2024-02-12 10:23:00 -08:00
ezbenchreport.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
ezbenchwarn.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
fastrandomstring.h Reduce header complexity 2023-11-28 14:39:42 -08:00
fixture.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
fixturerunner.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
formatbinaryasglyphs.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
formatbinaryashex.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
formatbool.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
formatfloat.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
formatint.c Fix ctype.h and wctype.h 2024-07-21 15:54:17 -07:00
formatrange.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
formatstr.c Fix ctype.h and wctype.h 2024-07-21 15:54:17 -07:00
getcore.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
geterrno.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
getinterrupts.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
globals.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
hexequals.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
hyperion.h Reduce header complexity 2023-11-28 14:39:42 -08:00
hyperion.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
hyperion.txt Initial import 2020-06-15 07:18:57 -07:00
incrementfailed.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
memoryexists.c Make realloc() go 100x faster on Linux/NetBSD 2024-07-07 12:40:30 -07:00
moby.h Reduce header complexity 2023-11-28 14:39:42 -08:00
moby.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
moby.txt Make improvements to redbean 2021-07-10 15:19:37 -07:00
polluteregisters.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
runner.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
seterrno.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
shoulddebugbreak.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
showerror.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
startswith.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
strcaseequals.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
strequals.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
strerror.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
subprocess.h Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
testcase.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
testlib.h Fix UB in gdtoa hexadecimal float scanf and strtod (#1288) 2024-09-14 17:11:04 -07:00
testmain.c Make it so the test harness closes fds up to 100 (#1268) 2024-08-29 16:12:53 -07:00
testrunner.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
thunks.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
tmptest.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
viewables.h Reduce header complexity 2023-11-28 14:39:42 -08:00
viewables.S Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
viewables.txt Do some string library work 2022-08-20 22:17:14 -07:00
waitforexit.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
waitforterm.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
yield.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00