tests/utils: do not test strbuf_example2() with buf=NULL

The following can be seen when building with CC=clang:

utils/utils_test.c:1239:2: runtime error: applying non-zero offset 99 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior utils/utils_test.c:1239:2 in
utils/utils_test.c:1241:3: runtime error: applying non-zero offset 99 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior utils/utils_test.c:1241:3 in
utils/utils_test.c:1242:2: runtime error: applying non-zero offset 99 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior utils/utils_test.c:1242:2 in
44. testsuite.at:274: 44. utils (testsuite.at:274): FAILED (testsuite.at:278)

This makes utils_test fail due to unexpected UBSan's output.

Even though passing NULL to the strbuf API is relatively safe, it makes
no sense and the API user should ensure that this never happens.  And
so we should not be testing this case.

Change-Id: Icd2323e93ec64afc1822d48e5e1d090083edf539
This commit is contained in:
Vadim Yanitskiy 2023-12-31 15:37:45 +07:00 committed by laforge
parent 5ce0131d43
commit 653c31e875
2 changed files with 0 additions and 4 deletions

View File

@ -1280,9 +1280,6 @@ void strbuf_test(void)
snprintf(buf, sizeof(buf), "0x2b 0x2b 0x2b...");
printf("4: (need %d chars, had size=0) %s\n", rc, buf);
rc = strbuf_example2(NULL, 99);
printf("5: (need %d chars, had NULL buffer)\n", rc);
printf("\ncascade:\n");
rc = strbuf_cascade(buf, sizeof(buf));
printf("(need %d chars)\n%s\n", rc, buf);

View File

@ -458,7 +458,6 @@ OSMO_STRBUF_PRINTF():
2: (need 42 chars, had size=42) T minus 10 9 8 7 6 5 4 3 2 1 ... Lift off
3: (need 42 chars, had size=42+1) T minus 10 9 8 7 6 5 4 3 2 1 ... Lift off!
4: (need 42 chars, had size=0) 0x2b 0x2b 0x2b...
5: (need 42 chars, had NULL buffer)
cascade:
(need 134 chars)