I used CFLAGS="-DNDEBUG -g2 -O1 -fsanitize=undefined". I built the
library, then ran a 'make test V=1'. The output presented to the user
looks OK. However, it looks like UBsan found some undefined behavior:

libunistring-0.9.10$ grep -IR 'runtime error'
tests/test-u8-width-linebreaks.log:unilbrk/u8-possible-linebreaks.c:49:3:
runtime error: null pointer passed as argument 1, which is declared to
never be null
tests/test-u32-to-u8.log:unistr/u8-cmp.c:38:10: runtime error: null
pointer passed as argument 2, which is declared to never be null
tests/test-numeric.log:unictype/numeric.c:52:54: runtime error: left
shift of 34927 by 16 places cannot be represented in type 'int'
tests/test-nfkc.log:unistr/u8-cmp.c:38:10: runtime error: null pointer
passed as argument 2, which is declared to never be null
tests/test-u8-tolower.log:unistr/u8-cmp.c:38:10: runtime error: null
pointer passed as argument 2, which is declared to never be null
tests/test-u16-to-u8.log:unistr/u8-cmp.c:38:10: runtime error: null
pointer passed as argument 2, which is declared to never be null
tests/test-nfkd.log:unistr/u8-cmp.c:38:10: runtime error: null pointer
passed as argument 2, which is declared to never be null
tests/test-u8-casefold.log:unistr/u8-cmp.c:38:10: runtime error: null
pointer passed as argument 2, which is declared to never be null
tests/unicase/test-ulc-casecmp2.sh.log:uniconv/u8-conv-from-enc.c:89:7:
runtime error: null pointer passed as argument 2, which is declared to
never be null
tests/unicase/test-ulc-casecoll2.sh.log:uniconv/u8-conv-from-enc.c:89:7:
runtime error: null pointer passed as argument 2, which is declared to
never be null
tests/test-nfc.log:unistr/u8-cmp.c:38:10: runtime error: null pointer
passed as argument 2, which is declared to never be null
tests/test-u8-totitle.log:unistr/u8-cmp.c:38:10: runtime error: null
pointer passed as argument 2, which is declared to never be null
tests/test-nfd.log:unistr/u8-cmp.c:38:10: runtime error: null pointer
passed as argument 2, which is declared to never be null
tests/test-u16-possible-linebreaks.log:unilbrk/u16-possible-linebreaks.c:49:3:
runtime error: null pointer passed as argument 1, which is declared to
never be null
tests/test-u16-width-linebreaks.log:unilbrk/u16-possible-linebreaks.c:49:3:
runtime error: null pointer passed as argument 1, which is declared to
never be null
tests/test-u8-toupper.log:unistr/u8-cmp.c:38:10: runtime error: null
pointer passed as argument 2, which is declared to never be null
tests/test-u8-possible-linebreaks.log:unilbrk/u8-possible-linebreaks.c:49:3:
runtime error: null pointer passed as argument 1, which is declared to
never be null

"runtime error: null pointer passed as argument <N>" is generally
benign under glibc, but musl is a different story. Musl believes in
early failures, and probably will deference the NULL pointer and
crash.

Be careful of these in the long run. The compiler is free to drop the
code because it is undefined behavior. My personal experience is,
little findings like these are the cause of obscure failures, like
self test failures on 32-bit ARM with GCC 5.0-5.2, while other
platforms will be OK.

Reply via email to