public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* strcpy and strcat seem to lead to a stack overflow
@ 2022-02-22 21:01 Emile Michel Hobo
  2022-02-23  0:47 ` Patrick McGehearty
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Emile Michel Hobo @ 2022-02-22 21:01 UTC (permalink / raw)
  To: gcc

Dear developers:

I find it counterintuitive that if I repeatedly reset a variable by using strcpy with an empty string "" to that variable and then us strcat to add characters to that variable that that seems to lead to a stack overflow.

I would expect strcpy to first free the variable, then malloc, then copy the string value into the variable. I think that would be a better interpretation, because it can keep running for quite some time before it overflows and doesn’t really call it.

Instead, I got "Illegal instruction: 4".

I ended up reimplementing the reset function, implementing it with free and malloc myself, but the way strings have been implemented in C is highly counter-intuitive. In general pointers tend to be bug-prone, but here you would expect this not to happen.

I hope you can fix this. Personally, I’m looking into switching to Ada.

All the best,


Emile M. Hobo


- Au fin! Et encore en plus. -


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

end of thread, other threads:[~2022-02-23  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 21:01 strcpy and strcat seem to lead to a stack overflow Emile Michel Hobo
2022-02-23  0:47 ` Patrick McGehearty
2022-02-23  8:58 ` lego12239
2022-02-23  9:47 ` Jonathan Wakely

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).