Re: strcmp() segfaults if one (and only one) of the parameters is NULL ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 5 Jul 2011 15:40:14 +0200
sundararaj reel <sundararaj.reel@xxxxxxxxxxxxxx> 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 "".

_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr


[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux