Commit 5989388c by David Malcolm Committed by David Malcolm

selftest.c: gracefully handle NULL in assert_streq

gcc/ChangeLog:
	* selftest.c (selftest::assert_streq): Handle NULL values of
	val_actual and val_expected.

From-SVN: r238479
parent 985a47b2
2016-07-19 David Malcolm <dmalcolm@redhat.com>
* selftest.c (selftest::assert_streq): Handle NULL values of
val_actual and val_expected.
2016-07-19 Martin Jambor <mjambor@suse.cz>
PR fortran/71688
......
......@@ -60,13 +60,25 @@ selftest::fail_formatted (const location &loc, const char *fmt, ...)
abort ();
}
/* Implementation detail of ASSERT_STREQ. */
/* Implementation detail of ASSERT_STREQ.
Compare val_expected and val_actual with strcmp. They ought
to be non-NULL; fail gracefully if either are NULL. */
void
selftest::assert_streq (const location &loc,
const char *desc_expected, const char *desc_actual,
const char *val_expected, const char *val_actual)
{
/* If val_expected is NULL, the test is buggy. Fail gracefully. */
if (val_expected == NULL)
::selftest::fail_formatted
(loc, "ASSERT_STREQ (%s, %s) expected=NULL",
desc_expected, desc_actual);
/* If val_actual is NULL, fail with a custom error message. */
if (val_actual == NULL)
::selftest::fail_formatted
(loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=NULL",
desc_expected, desc_actual, val_expected);
if (0 == strcmp (val_expected, val_actual))
::selftest::pass (loc, "ASSERT_STREQ");
else
......
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