public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Reg seg. violations
@ 2006-07-16 22:09 Bill McEnaney
  2006-07-17  9:01 ` Andrew Haley
  0 siblings, 1 reply; 4+ messages in thread
From: Bill McEnaney @ 2006-07-16 22:09 UTC (permalink / raw)
  To: Vivek Katakam, gcc-help

Maybe another problem is that getenv() expects a pointer, not a string
literal.  It seems to me although a pointer can point to a string
literal, a string literal can't point to anything.  If I'm mistaken,
would someone please say so?

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reg seg. violations
  2006-07-16 22:09 Reg seg. violations Bill McEnaney
@ 2006-07-17  9:01 ` Andrew Haley
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Haley @ 2006-07-17  9:01 UTC (permalink / raw)
  To: Bill McEnaney; +Cc: Vivek Katakam, gcc-help

Bill McEnaney writes:
 > Maybe another problem is that getenv() expects a pointer, not a string
 > literal.  It seems to me although a pointer can point to a string
 > literal, a string literal can't point to anything.  If I'm mistaken,
 > would someone please say so?

You're mistaken.

getenv() expects a const char*, and a string literal has a type
char[], which is compatible.

Andrew.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reg seg. violations
@ 2006-07-16 21:57 Bill McEnaney
  0 siblings, 0 replies; 4+ messages in thread
From: Bill McEnaney @ 2006-07-16 21:57 UTC (permalink / raw)
  To: Vivek Katakam, gcc-help

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Reg seg. violations
@ 2006-07-16 18:58 Vivek Katakam
  0 siblings, 0 replies; 4+ messages in thread
From: Vivek Katakam @ 2006-07-16 18:58 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-07-17  9:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-16 22:09 Reg seg. violations Bill McEnaney
2006-07-17  9:01 ` Andrew Haley
  -- strict thread matches above, loose matches on Subject: below --
2006-07-16 21:57 Bill McEnaney
2006-07-16 18:58 Vivek Katakam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).