Fix double-NULL case.

Fix null pointer dereference in t_compare_mem() and t_compare_str() when both the expected value and the received value are NULL.
This commit is contained in:
Dag-Erling Smørgrav 2019-02-20 14:07:47 +01:00
parent c31fe69263
commit 52364cd8d9

View file

@ -110,7 +110,8 @@ t_compare_mem(const void *expected, const void *received, size_t len)
t_printv("\n"); t_printv("\n");
t_printv("received null pointer\n"); t_printv("received null pointer\n");
return (0); return (0);
} else if (memcmp(expected, received, len) != 0) { } else if (expected != NULL && received != NULL &&
memcmp(expected, received, len) != 0) {
t_printv("expected "); t_printv("expected ");
t_printv_hex(expected, len); t_printv_hex(expected, len);
t_printv("\n"); t_printv("\n");
@ -137,7 +138,8 @@ t_compare_str(const char *expected, const char *received)
t_printv("expected \"%s\"\n", expected); t_printv("expected \"%s\"\n", expected);
t_printv("received null pointer\n"); t_printv("received null pointer\n");
return (0); return (0);
} else if (strcmp(expected, received) != 0) { } else if (expected != NULL && received != NULL &&
strcmp(expected, received) != 0) {
t_printv("expected %s\n", expected); t_printv("expected %s\n", expected);
t_printv("received %s\n", received); t_printv("received %s\n", received);
return (0); return (0);