"Segmentation fault (core dumped)" error
FComegys@aol.com
FComegys@aol.com
Fri Jul 6 23:24:00 GMT 2001
I am a software engineer with decades of experience writing C in Vax, Dos &
Windows environments. This is my first experience with gcc on Unix (actually
Linux).
I have written a program to be run as a CGI script which returns a Web page
with a list of filenames (or HTML titles). The program is Ansi-C compliant
except for reading directories and case insensitive string compare functions
which are compiler dependent. It was originally developed using MS VC++
(please try not to gag). I am testing it on a Red Hat Linux Web server via
Telnet.
gcc -v returns "gcc version 2.7.2.3 I386-Red Hat-Linux"
My problem involves a "Segmentation fault (core dumped)" error. I have no
idea of what this error message is trying to tell me. I located a gcc
compiler from
Cygwin.com in order to get documentation on the compiler. The man and
textinfo utilities say I need a later version of Windows to run them.
The "Segmentation fault (core dumped)" error always occurs in the same
function but at different points. I am certain that it is not caused by a
random store (bad pointer).
In fact the LESS the function is asked to do, the EARLIER the error occurs.
That is:
void myfunc(char *fspec, int sorting, int subdirs, other args)
{
/* code to allocate the array of path names and add current dir as the first
entry */
if ( subdirs)
{
GetDirPaths(); /* recursively adds path strings for all subdirs to a
heap array */
if (sorting)
{
/* code to sort the pointers to the path strings */
}
}
for (i=0; i < numberofpaths; i++)
{
/* code to list files that match fspec and free path string to this dir
*/
}
}
When subdirs==0 the error occurs entering the for loop but when subdirs==1
the error occurs exiting the for loop. When I link in my remaining portion of
my program, the error occurs returning from the last recursive call to
GetDirPaths(). When I modified GetDirPaths not to recursively call itself but
return the number of unread dirs found the error occured calling myfunc! HELP!
I am pretty certain that this error is not caused by faulty program logic at
the source level. My guess is that it is related to compile/link options that
may be necessary for i386 machines, expanding heap size or pointer size, or
stack size or some other
such reason.
I build the program with:
gcc -o myprog.cgi myprog.c with default CCFLAGS or CCFLAGS=
An explanation of what a "Segmentation fault (core dumped)" error actually
is or any hint as what compilier/link options to use or any other push in the
right direction would be greatly appreciated.
Thank you in advance for your assistance,
Frank Comegys
fcomegys@aol.com
ps. I know that I can read both the dirs and files in one pass using gcc and
intend to do so after I develop a fnmatch function for MSVC++ which
currently requires me to
findfirst(*.*, other args) and check if dir then findfirst(fspec, other args)
to find targeted files.
Frank Comegys
fcomegys@aol.com
More information about the Gcc-help
mailing list