Commit bf7f70ff by David Malcolm Committed by David Malcolm

selftest.c: remove calls to strndup (PR bootstrap/78616)

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
parent 6556f651
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> 2016-12-02 Michael Meissner <meissner@linux.vnet.ibm.com>
PR target/78639 PR target/78639
...@@ -200,41 +200,35 @@ read_file (const location &loc, const char *path) ...@@ -200,41 +200,35 @@ read_file (const location &loc, const char *path)
/* Selftests for libiberty. */ /* Selftests for libiberty. */
/* Verify that both strndup and xstrndup generate EXPECTED /* Verify that xstrndup generates EXPECTED when called on SRC and N. */
when called on SRC and N. */
static void 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); char *buf = xstrndup (src, n);
if (buf)
ASSERT_STREQ (expected, buf);
free (buf);
buf = xstrndup (src, n);
ASSERT_STREQ (expected, buf); ASSERT_STREQ (expected, buf);
free (buf); free (buf);
} }
/* Verify that strndup and xstrndup work as expected. */ /* Verify that xstrndup works as expected. */
static void static void
test_strndup () test_xstrndup ()
{ {
assert_strndup_eq ("", "test", 0); assert_xstrndup_eq ("", "test", 0);
assert_strndup_eq ("t", "test", 1); assert_xstrndup_eq ("t", "test", 1);
assert_strndup_eq ("te", "test", 2); assert_xstrndup_eq ("te", "test", 2);
assert_strndup_eq ("tes", "test", 3); assert_xstrndup_eq ("tes", "test", 3);
assert_strndup_eq ("test", "test", 4); assert_xstrndup_eq ("test", "test", 4);
assert_strndup_eq ("test", "test", 5); assert_xstrndup_eq ("test", "test", 5);
/* Test on an string without zero termination. */ /* Test on an string without zero termination. */
const char src[4] = {'t', 'e', 's', 't'}; const char src[4] = {'t', 'e', 's', 't'};
assert_strndup_eq ("", src, 0); assert_xstrndup_eq ("", src, 0);
assert_strndup_eq ("t", src, 1); assert_xstrndup_eq ("t", src, 1);
assert_strndup_eq ("te", src, 2); assert_xstrndup_eq ("te", src, 2);
assert_strndup_eq ("tes", src, 3); assert_xstrndup_eq ("tes", src, 3);
assert_strndup_eq ("test", src, 4); assert_xstrndup_eq ("test", src, 4);
} }
/* Run selftests for libiberty. */ /* Run selftests for libiberty. */
...@@ -242,7 +236,7 @@ test_strndup () ...@@ -242,7 +236,7 @@ test_strndup ()
static void static void
test_libiberty () test_libiberty ()
{ {
test_strndup (); test_xstrndup ();
} }
/* Selftests for the selftest system itself. */ /* Selftests for the selftest system itself. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment