This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Reg seg. violations
- From: "Bill McEnaney" <bill at rkirkpat dot net>
- To: "Vivek Katakam" <vivek1717 at gmail dot com>, gcc-help at gcc dot gnu dot org
- Date: Sun, 16 Jul 2006 15:57:48 -0600 (MDT)
- Subject: Re: Reg seg. violations
I hear that segmenation faults happen when the computer tries to follow
a null pointer. the getenv() function returns NULL when that function
fails. So why not try something likes this?
printf("Content-type: text/html\n\n");
if (getenv("QUERY_STRING") != NULL)
{
line_buffer = (char *) malloc(strlen(QUERY_STRING) + 1);
strcpy(line_buffer, getenv("QUERY_STRING");
}
Bill
Vivek Katakam wrote:
> Hi all
>
> I am mainly getting segmentation violation at this code in strlen and
strcpy:
>
> printf("Content-type: text/html\n\n");
> line_buffer = (char *) malloc(strlen(getenv("QUERY_STRING")) + 1);
> strcpy(line_buffer, getenv("QUERY_STRING"));
>
> at strlen and strcpy when QUERY_STRING is not set .
> Is there a way to handle this? there are a lot of such occurrences.
>
> Regards,
> Vivek
>
>
________________________________________________________________
"Pro-choice?" Then click here.
http://cathinsight.com/morality/saying.htm
"Men must look for the peace of Christ in the Kingdom of Christ... When
once men recognize, both in private and in public life, that Christ is
King, society will at last receive the great blessings of real liberty,
well-ordered discipline, peace and harmony." Pope Pius XI