char *p; placement and mysterious segfault on sprintf(p, "%d", 3);

Nick Patavalis npat@inaccessnetworks.com
Mon May 19 19:09:00 GMT 2003


On Mon, May 19, 2003 at 01:51:06PM -0400, Dave King wrote:
> Tom,
> 
> If I read your response correctly, solution to this problem is to allocated
> enough space for the buffer p? Is this a bug in gcc or just not setting up
> sprintf correctly? 

NO IT IS NO GCC BUG! 

Every compiler must behave the same way.  You programm is
incorrect. The "p" you are passing to "sprintf" is pointer pointing to
a, for all we know, *random* address. No space is allocated there.

/npat

-- 
A computer lets you make more mistakes faster than any invention in human
history, with the possible exceptions of handguns and tequila.
  -- Mitch Ratcliffe, Technology Review, April 1992 



More information about the Gcc-help mailing list