summaryrefslogtreecommitdiff
path: root/cord/tests
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-04-25 23:22:58 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-04-25 23:24:03 +0300
commite90fce7c34474f175fcf47ec614bac58b447416d (patch)
tree91269aa2b95f6498b433a0a9c845540a3903f817 /cord/tests
parentd82755f6fbdad03226eac6d70815e32db9ffcf4d (diff)
downloadbdwgc-e90fce7c34474f175fcf47ec614bac58b447416d.tar.gz
Eliminate 'ISO C++98 does not support z gnu_printf modifier' gcc warning
(fix of commit d82755f6f) Issue #439 (bdwgc). * cord/tests/cordtest.c (zu_format): New global variable. * cord/tests/cordtest.c (test_printf): Pass zu_format variable (instead of "%zu") to GC_SNPRINTF (and sprintf); add comment; print a message if res!=1.
Diffstat (limited to 'cord/tests')
-rw-r--r--cord/tests/cordtest.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/cord/tests/cordtest.c b/cord/tests/cordtest.c
index ca1304be..bb8d4975 100644
--- a/cord/tests/cordtest.c
+++ b/cord/tests/cordtest.c
@@ -272,6 +272,8 @@ int wrap_vfprintf(FILE * f, CORD format, ...)
# endif
#endif
+/* no static */ /* no const */ char *zu_format = "%zu";
+
void test_printf(void)
{
CORD result;
@@ -305,9 +307,11 @@ void test_printf(void)
if (CORD_cmp(result, result2) != 0) ABORT("CORD_sprintf goofed 5");
# ifdef GC_SNPRINTF
- res = GC_SNPRINTF(result2, sizeof(result2), "%zu", (size_t)0);
+ /* Check whether "%zu" specifier is supported; pass the format */
+ /* string via a variable to avoid a compiler warning if not. */
+ res = GC_SNPRINTF(result2, sizeof(result2), zu_format, (size_t)0);
# else
- res = sprintf(result2, "%zu", (size_t)0);
+ res = sprintf(result2, zu_format, (size_t)0);
# endif
result2[sizeof(result2) - 1] = '\0';
if (res == 1) /* is "%z" supported by printf? */ {
@@ -316,6 +320,8 @@ void test_printf(void)
ABORT("CORD_sprintf failed 5");
if (CORD_cmp(result, "123 4567 0x4abc") != 0)
ABORT("CORD_sprintf goofed 5");
+ } else {
+ (void)CORD_printf("printf lacks support of 'z' modifier\n");
}
/* TODO: Better test CORD_[v][f]printf. */