From: Emile Michel Hobo <e.m.hobo@hotmail.nl>
To: gcc@gcc.gnu.org
Subject: strcpy and strcat seem to lead to a stack overflow
Date: Tue, 22 Feb 2022 22:01:47 +0100 [thread overview]
Message-ID: <AM6P194MB0263B192623F4BBFD53A4C10AE3B9@AM6P194MB0263.EURP194.PROD.OUTLOOK.COM> (raw)
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. -
next reply other threads:[~2022-02-22 21:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 21:01 Emile Michel Hobo [this message]
2022-02-23 0:47 ` Patrick McGehearty
2022-02-23 8:58 ` lego12239
2022-02-23 9:47 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM6P194MB0263B192623F4BBFD53A4C10AE3B9@AM6P194MB0263.EURP194.PROD.OUTLOOK.COM \
--to=e.m.hobo@hotmail.nl \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).