Red Hat Bugzilla – Bug 145840
Incorrect or missing memory allocation for variable
Last modified: 2007-11-30 17:10:58 EST
Description of problem:
gcc doesn't appear to correctly allocate memory for a variable
Version-Release number of selected component (if applicable):
I tried everything I could to get it to work. I spent about 4 hours
on this issue with no solution other than the one described below.
Steps to Reproduce:
<shortened code snippet begins>
static int dbug12_get_reply (unsigned char *packet)
void dbug12_stop_reason (enum dbug12_stop *reason, int *sigrc)
unsigned char reply;
// This line is needed
//to make the code work
replyEnd = 0;
// get the reply
replyEnd = dbug12_get_reply(reply);
printf("Reply is %s\n",reply);
// handle the error condition
// can't pass here with a zero length
if (replyEnd == 0)
<end of shortned code snippet>
Problem #1: gdb cannot find replyEnd:
(gdb) whatis replyEnd
No symbol "replyEnd" in current context.
The code doesn't execute properly if I delete the "replyEnd = 0;"
line. Without "replyEnd = 0;" in the code, replyEnd gets an
unalterable junk value. With "replyEnd = 0;" in the code, replyEnd
gets set to the return value of 5, which it should.
I was also playing around with changing the size of the reply buffer,
ie "reply", reply, etc. It didn't look like gcc was
changing the size of the buffer on a clean build.
If the included code snippet doesn't reproduce the problem, I can
provide the volumous code sample that does.
gcc is being run from kdevelop. The gcc command line switches used
are -ggdb only.
Such incomplete snippets are useless, only self-contained (and ideally
preprocessed) testcase helps.
BTW, you are printing uninitialized buffer in the incomplete snippet above.
I have cut'n'pasted it and fixed it so that it compiles, but replyEnd var
is definitely there, visible to the debugger and removing replyEnd = 0; doesn't
I stripped everything out of dbug12_get_reply(). It used to set a value for reply.
How are you confirming that varEnd is there for the debugger to use ?
I mean, where and how are you confirming that the var is getting created and/or
Adding and removing replyEnd changes whether or not replyEnd gets the return
value from dbug12_get_reply() on my machine. gdb cannot get replyEnd no matter
what I do.
I'll see if I can create a test case or better illustrate what is going on.
Have you managed to create a test case yet? Without it it is really hard
to talk about this.
Closing until you provide a testcase. When you have it, please reopen.