[LCP]Seg fault

Andrew Weaver Andrew.Weaver at tecnomen.fi
Fri Dec 13 21:49:01 UTC 2002


On Friday, December 13, 2002 3:15 PM, mehul radheshyam choube
[SMTP:mrc_cprog at rediffmail.com] wrote:
> hi all,
>  	i m getting segfault. but unable to get the reasons why. 
> please
> go through the following code :-
> 
> /*
>   * creates folder.
>   * returns 0 if successful else non-zero value.
>   */
> int createDir(char *dirName)
> {
>  	char *str = NULL, *str1 = NULL;
>  	char *name = NULL, *name1 = NULL;
> 
>  	str = str1 = name1 = dirName;
>  	printf("str     = %s\n", str);
>  	printf("str1    = %s\n", str1);
>  	printf("name1   = %s\n", name1);
>  	printf("dirName = %s\n", dirName);
> }
> 
> static void handle_import(int connfd, void *arg1, void *arg2)
> {
>  	ImportOptions *impOptions = (ImportOptions *)arg2;
>  	UserInfo      *userInfo = (UserInfo *)arg1;
> 
>  	createDir(userInfo->userName);
> }
> 
>  	the output is following :-
> 
> str     = mehul
> str1    = mehul
> name1   = mehul
> dirName = mehul
> 
>  	but the program seg faults at first printf() in createDir().

*** Huh? How come you get the output then?

> the gdb says following :-
> 
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 1026 (LWP 2059)]
> 0x400efc66 in _IO_vfprintf (s=0x40071cc0, format=0x805161b "str     
> = %s\n",
>      ap=0xbf7ff764) at ../sysdeps/i386/i486/bits/string.h:529
> 529     ../sysdeps/i386/i486/bits/string.h: No such file or 
> directory.
> 
>  	waiting for reply.
> 
> mehul.
> 
> 
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List



More information about the linuxCprogramming mailing list