aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/selftest.c14
2 files changed, 18 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c25a1d3..4d4cd9b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/selftest.c b/gcc/selftest.c
index ed6e517..76a4c41 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -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