This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


"Dave King" <dking04@comcast.net> writes:

> Tom,
> 
> If I read your response correctly, solution to this problem is to allocated
> enough space for the buffer p?

Yes. If you do not provide enough space for what vsnprintf writes to
    the buffer, you get undefined behavior, and it is *you* who has a
    bug, not gcc.

> Is this a bug in gcc

99.9% of the time, suspecting your compiler of bugs is a sign that you
   need to get outside more. Leave your cube, office, mushroom farm,
   etc, and go for a walk. (This advice comes from personal experience.)

No this is not a bug in gcc.

> or just not setting up
> sprintf correctly?

This is the problem.

> I have run into this same problem and it has been driving
> nuts.
[snip]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]