This is the mail archive of the gcc-bugs@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]

[Bug c/42799] Variable unexpectedly set to 0 because a scanf()



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


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