Hi,
strcmp() returns 0 if both are parameters NULL, but segfaults if one of the parameters is NULL.
Is this a known behaviour ? man page says nothing about NULL parameters. I ask because, vdr checks for NULL parameter(s) to strcmp() sometimes.
Check for one or both parameters: epg.c:692: if (shortText && strcmp(title, shortText) == 0) { epg.c:742: if (shortText && description && strcmp(shortText, description) == 0) {
No check for null parameter: channels.c:227: bool nn = strcmp(name, Name) != 0; channels.c:228: bool ns = strcmp(shortName, ShortName) != 0;
On Tue, 5 Jul 2011 15:40:14 +0200 sundararaj reel sundararaj.reel@googlemail.com wrote:
strcmp() returns 0 if both are parameters NULL, but segfaults if one of the parameters is NULL.
I think that's officially undefined behaviour. The easiest workaround (in the absence of something like glib which provides NULL-safe versions of some str functions) is to use strcmp(s1 ? s1 : "", s2 ? s2 : "") but only if it doesn't matter that NULL compares equal to "".