From f2e7f24daaa43c0927130b6ed02c3ed17689b3ca Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 6 Sep 2024 13:36:15 +0200 Subject: Work around a gcc warning It seems that annotating sprintf with `write` makes gcc unhappy, as its analyser is unable to understand that we're checking if `__b != -1` before calling `__orig_snprintf`, so let's comment this annotation for now. --- tests/Makefile | 2 ++ tests/test_sprintf.c | 8 ++++++++ tests/test_sprintf_62.c | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/test_sprintf.c create mode 100644 tests/test_sprintf_62.c (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index d29a87d..333f088 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -96,6 +96,8 @@ RUNTIME_TARGETS= \ test_send_static \ test_sendto_dynamic \ test_sendto_static \ + test_sprintf \ + test_sprintf_62 \ test_stpcpy_dynamic_write \ test_stpcpy_overwrite_over \ test_stpcpy_overwrite_under \ diff --git a/tests/test_sprintf.c b/tests/test_sprintf.c new file mode 100644 index 0000000..edde838 --- /dev/null +++ b/tests/test_sprintf.c @@ -0,0 +1,8 @@ +#include "common.h" + +#include + +int main(int argc, char** argv) { + char buffer[12] = {0}; + sprintf(buffer, "%s", "1234567"); +} diff --git a/tests/test_sprintf_62.c b/tests/test_sprintf_62.c new file mode 100644 index 0000000..3a84a1f --- /dev/null +++ b/tests/test_sprintf_62.c @@ -0,0 +1,21 @@ +#include "common.h" + +#include + +static char *offstr(char *str) +{ + int len = 0; + + len = sprintf(str, "%s+0x%lx", "foo", (long unsigned int)0); + sprintf(str+len, " (%s+0x%lx)","bar", (long unsigned int)0); + if (len < 0) + return NULL; + return str; +} + +int main() { + char buf[100]; + char *c = offstr(buf); + printf("%s\n", c); + return 0; +} -- cgit v1.3