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

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

 



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;


-- 
Thanks,
Sundararaj



$ /lib/libc.so.6
GNU C Library (Ubuntu EGLIBC 2.11.1-0ubuntu7.7) stable release version
2.11.1, by Roland McGrath et al.
...
Compiled by GNU CC version 4.4.3.
Compiled on a Linux >>2.6.24-28-server<< system on 2011-01-11.
Available extensions:
	crypt add-on version 2.1 by Michael Glad and others
	GNU Libidn by Simon Josefsson
	Native POSIX Threads Library by Ulrich Drepper et al
	BIND-8.2.3-T5B



/*---------------------------------------------------------------*/

#include <string.h>
#include <stdio.h>

int main()
{
    int nn;

    printf("trying strcmp(NULL,NULL)\n");
    nn = strcmp(NULL, NULL); /* no segfault */

    printf("trying strcmp(\"non null string\",NULL)\n");
    nn = strcmp("non null string", NULL);  /* segfault */

    printf("does not reach here\n");

    return 0;
} /* main() */

/*-------------------------------------------------------------------*/


in gdb I get this backtrace
#0  __strcmp_ia32 () at ../sysdeps/i386/i686/multiarch/../strcmp.S:40

_______________________________________________
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