This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/7108: gcc 3.1 initialize two times the same variable
- From: quequero at linux dot bitchx dot it
- To: gcc-gnats at gcc dot gnu dot org
- Cc: quequero at linux dot bitchx dot it
- Date: 24 Jun 2002 20:44:16 -0000
- Subject: optimization/7108: gcc 3.1 initialize two times the same variable
- Reply-to: quequero at linux dot bitchx dot it
>Number: 7108
>Category: optimization
>Synopsis: gcc 3.1 initialize two times the same variable
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Mon Jun 24 13:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: gcc 3.1 Thread model: single
>Release: 3.1
>Organization:
>Environment:
Linux 2.4.18 #16 Tue May 28 14:07:34 CEST 2002 i686
>Description:
Look here:
void function(char *string){
char buffer[100];
int i=0;
....
Now, let's disassemble it (i have used stripped and non-stripped version of the executable):
.text:08048492 push ebp
.text:08048493 mov ebp, esp
.text:08048495 sub esp, 98h
.text:0804849B mov [ebp+i], 0
.text:080484A2 mov [ebp+i], 0
the same variable is initiaziled twice :)
>How-To-Repeat:
i've discovered it compiling a silly program that i'm writing for a demonstration:
void overflow(char *string);
int main(int argv, char *argc[]){
overflow(argc[1]);
}
void overflow(char *string){
char buffer[100];
int i=0;
for(i=0; i<=100; i++)
buffer[i] = string[i];
printf("Typed: %s\n", buffer);
}
the disassembling the funciot "overflow" with IDA:
.text:0804849B mov [ebp+i], 0
.text:080484A2 mov [ebp+i], 0
i can see that "int i" is initialized twice to 0 but as you can see ebp doesn't change so that instruction shouldn't be there :P
>Fix:
i really don't know
>Release-Note:
>Audit-Trail:
>Unformatted: