When Octave (which uses gnulib) is compiled with UBSAN I see the following while running its test suite:
../../libgnu/unistr/u8-to-u16.c:80:34: runtime error: applying zero offset to null pointer SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../libgnu/unistr/u8-to-u16.c:80:34 ../../libgnu/unistr/u16-to-u8.c:80:33: runtime error: applying zero offset to null pointer SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../libgnu/unistr/u16-to-u8.c:80:33 Looking at the sourse I see the line count = u16_uctomb(result + length, uc, allocated - length); So at the begging of the loop "length" is 0 but "result" is NULL, so technically this is NULL pointer arithmetics, and UBSAN does not like it. I am not even 100% sure this is a bug, but the diffs: @@ -77,7 +77,11 @@ s += count; /* Store it in the output string. */ - count = u16_uctomb (result + length, uc, allocated - length); + if (result != NULL) + count = u16_uctomb (result + length, uc, allocated - length); + else + count = -2; /* Need for allocation */ + if (count == -1) { if (!(result == resultbuf || result == NULL)) and @@ -77,7 +77,11 @@ s += count; /* Store it in the output string. */ - count = u8_uctomb (result + length, uc, allocated - length); + if (result != NULL) + count = u8_uctomb (result + length, uc, allocated - length); + else + count = -2; /* Need for allocation */ + if (count == -1) { if (!(result == resultbuf || result == NULL)) silenced UBSAN for me. Dmitri. --