Closed GoogleCodeExporter closed 8 years ago
probably sprintf-chk.c suffers from the same problem.
Original comment by jmoc...@gmail.com
on 12 Jan 2009 at 11:38
as suspected, the problem is in pointer dereferencing. here is a minimal
testcase:
#include <stdarg.h>
#include <string.h>
int l = 0;
char *ptr = "blabla";
char *init = "1234567890";
char buf[32];
char b = 'b';
extern sprintf(char *s, char *fmt, ...);
extern void abort();
int
main(int argc, char *argv)
{
strcpy(buf, init);
sprintf(buf, "%d - %c", (int)(l + 12), *ptr);
if(buf[5] != 'b')
abort();
return 0;
}
replacing *ptr with (char)'b' works. also putting an ordinary (not dereferenced
ptr)
char var there works.
Original comment by jmoc...@gmail.com
on 15 Jan 2009 at 11:52
indeed, this is a dup of issue 84.
when minimal test case above is built with -O1, the initial expansion of the
dereferencing of the ptr loads mem from address in psuedo reg 147:
(insn 31 30 32 (set (reg:SI 148)
(zero_extend:SI (mem:QI (reg/f:DI 147) [0 S1 A8]))) -1 (nil)
(nil))
all fine and dandy, except for the fact that nothing was ever loaded to reg
147, and
in particular not ptr address, which we'd expect ...
Original comment by jmoc...@gmail.com
on 15 Jan 2009 at 12:20
Original issue reported on code.google.com by
jmoc...@gmail.com
on 12 Jan 2009 at 11:37