This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/42799] Variable unexpectedly set to 0 because a scanf()
- From: "jakub at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jan 2010 10:21:56 -0000
- Subject: [Bug c/42799] Variable unexpectedly set to 0 because a scanf()
- References: <bug-42799-18690@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from jakub at gcc dot gnu dot org 2010-01-19 10:21 -------
This is undefined behavior, scanf is writing int value into an unsigned short
variable, so it of course can overwrite whatever happens to be adjacent to that
var on the stack.
Use %hd instead of %d to write to short/unsigned short vars in scanf format
string, or write to int variable instead.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42799