[PATCH] dive.c:merge_text(): Slighly better string merge logic

Dirk Hohndel dirk at hohndel.org
Fri Mar 8 10:12:57 PST 2013


"Lubomir I. Ivanov" <neolit123 at gmail.com> writes:

> On 8 March 2013 20:06, Dirk Hohndel <dirk at hohndel.org> wrote:
>> That's what I ended up doing:
>>
>> diff --git a/dive.c b/dive.c
>> index 1b4c783..034fb15 100644
>> --- a/dive.c
>> +++ b/dive.c
>> @@ -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;
>>
>>
>
> yep, i think it covers all cases.

And once you add the missing semicolon in line 911 it even compiles :-)

Pushed

Thanks for the analysis and help.

/D


More information about the subsurface mailing list