selftest.c: remove calls to strndup (PR bootstrap/78616)
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 2 Dec 2016 22:39:43 +0000 (22:39 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Fri, 2 Dec 2016 22:39:43 +0000 (22:39 +0000)
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.

From-SVN: r243207

gcc/ChangeLog
gcc/selftest.c

index 19394b0..18efa04 100644 (file)
@@ -1,3 +1,13 @@
+2016-12-02  David Malcolm  <dmalcolm@redhat.com>
+
+       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.
+
 2016-12-02  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        PR target/78639
index 6df73c2..40c6cb5 100644 (file)
@@ -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.  */