As part of the fix for PR c/78498 I added selftests for xstrndup in r243030, and seeing the implementation of strndup in libiberty, I also made the selftests verify strndup.
This turned out to be overzealous, as strndup is not necessarily available in every configuration when the selftests run. This patch removes the testing for strndup (but not for xstrndup). Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. Committed to trunk as r243207 (as "obvious") gcc/ChangeLog: PR bootstrap/78616 * selftest.c (selftest::assert_strndup_eq): Rename to... (selftest::assert_xstrndup_eq): ...this, and remove call to strndup. (selftest::test_strndup): Rename to... (selftest::test_xstrndup): ...this, updating for above renaming. (selftest::test_libiberty): Update for renaming. --- gcc/selftest.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/gcc/selftest.c b/gcc/selftest.c index 6df73c2..40c6cb5 100644 --- a/gcc/selftest.c +++ b/gcc/selftest.c @@ -200,41 +200,35 @@ read_file (const location &loc, const char *path) /* Selftests for libiberty. */ -/* Verify that both strndup and xstrndup generate EXPECTED - when called on SRC and N. */ +/* Verify that xstrndup generates EXPECTED when called on SRC and N. */ static void -assert_strndup_eq (const char *expected, const char *src, size_t n) +assert_xstrndup_eq (const char *expected, const char *src, size_t n) { - char *buf = strndup (src, n); - if (buf) - ASSERT_STREQ (expected, buf); - free (buf); - - buf = xstrndup (src, n); + char *buf = xstrndup (src, n); ASSERT_STREQ (expected, buf); free (buf); } -/* Verify that strndup and xstrndup work as expected. */ +/* Verify that xstrndup works as expected. */ static void -test_strndup () +test_xstrndup () { - assert_strndup_eq ("", "test", 0); - assert_strndup_eq ("t", "test", 1); - assert_strndup_eq ("te", "test", 2); - assert_strndup_eq ("tes", "test", 3); - assert_strndup_eq ("test", "test", 4); - assert_strndup_eq ("test", "test", 5); + assert_xstrndup_eq ("", "test", 0); + assert_xstrndup_eq ("t", "test", 1); + assert_xstrndup_eq ("te", "test", 2); + assert_xstrndup_eq ("tes", "test", 3); + assert_xstrndup_eq ("test", "test", 4); + assert_xstrndup_eq ("test", "test", 5); /* Test on an string without zero termination. */ const char src[4] = {'t', 'e', 's', 't'}; - assert_strndup_eq ("", src, 0); - assert_strndup_eq ("t", src, 1); - assert_strndup_eq ("te", src, 2); - assert_strndup_eq ("tes", src, 3); - assert_strndup_eq ("test", src, 4); + assert_xstrndup_eq ("", src, 0); + assert_xstrndup_eq ("t", src, 1); + assert_xstrndup_eq ("te", src, 2); + assert_xstrndup_eq ("tes", src, 3); + assert_xstrndup_eq ("test", src, 4); } /* Run selftests for libiberty. */ @@ -242,7 +236,7 @@ test_strndup () static void test_libiberty () { - test_strndup (); + test_xstrndup (); } /* Selftests for the selftest system itself. */ -- 1.8.5.3