Don't strdup(NULL)

merge_text() could call strdup(NULL) if one pointer was "" and the other
NULL. This commit fixes that.

Reported-by: fhuberts
Analyzed-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-03-08 10:06:59 -08:00
parent dac29e7bc4
commit 473bc91c8a

4
dive.c
View file

@ -908,11 +908,11 @@ static char *merge_text(const char *a, const char *b)
if (!a && !b)
return NULL;
if (!a || !*a)
return strdup(b);
return b ? strdup(b) : NULL;
if (!b || !*b)
return strdup(a);
if (!strcmp(a,b))
return strdup(a);
return a ? strdup(a) : NULL;
res = malloc(strlen(a) + strlen(b) + 32);
if (!res)
return (char *)a;