From: David Malcolm Date: Tue, 19 Jul 2016 16:16:18 +0000 (+0000) Subject: selftest.c: gracefully handle NULL in assert_streq X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5989388cdfa7b757a9aab117f4dcabea147050a8;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c25a1d38e08..4d4cd9b44e8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-07-19 David Malcolm + + * selftest.c (selftest::assert_streq): Handle NULL values of + val_actual and val_expected. + 2016-07-19 Martin Jambor PR fortran/71688 diff --git a/gcc/selftest.c b/gcc/selftest.c index ed6e517f00e..76a4c414947 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