Bug 145840 - Incorrect or missing memory allocation for variable
Incorrect or missing memory allocation for variable
Product: Fedora
Classification: Fedora
Component: gcc34 (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2005-01-21 22:27 EST by Kim Lux
Modified: 2007-11-30 17:10 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-03-01 07:25:04 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Kim Lux 2005-01-21 22:27:33 EST
Description of problem: 
gcc doesn't appear to correctly allocate memory for a variable 
Version-Release number of selected component (if applicable): 
How reproducible: 
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) 
return 5;  
void dbug12_stop_reason (enum dbug12_stop *reason, int *sigrc) 
  int replyEnd;  
  unsigned char reply[254]; 
  // 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. 
Problem #2: 
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[255]", reply[253], etc.  It didn't look like gcc was 
changing the size of the buffer on a clean build.  
Additional info: 
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.
Comment 1 Jakub Jelinek 2005-01-24 09:30:29 EST
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
change anything.
Comment 2 Kim Lux 2005-01-24 13:26:07 EST
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
set ?

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.  
Comment 3 Jakub Jelinek 2005-02-21 10:37:44 EST
Have you managed to create a test case yet?  Without it it is really hard
to talk about this.
Comment 4 Jakub Jelinek 2005-03-01 07:25:04 EST
Closing until you provide a testcase.  When you have it, please reopen.

Note You need to log in before you can comment on or make changes to this bug.