[LCP]Seg fault

Aron Stansvik elvstone at home.se
Fri Dec 13 23:07:01 UTC 2002


I tried your createDir()-function, and it worked (although you should compile your code with -Wall, it will make you a better programmer) without any segfaults. Are you sure that is where the program crashes?

/ elvis

-----Original Message-----
From: "mehul radheshyam choube" <mrc_cprog at rediffmail.com>
To: linuxcprogramming at lists.linux.org.au
Date: 13 Dec 2002 13:14:41 -0000 
Subject: [LCP]Seg fault

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().
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