The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 11-21-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
The only possible situation here is that block2 or block3 are overflowing a variable on your function's stack and your y var is being changed.

A function's stack is composed (growing from high memory to low memory) by variables (in reverse order), eip, esp, function name and esp.

Here is a simple example for your possible situation:
Code:
void of()
{
    char a[10];
    char b[10];
    strcpy (a, "aaaaaaaaaa");
    printf ("%s\n", a);
    strcpy(b, "bbbbbbbbbboverflow");
    printf ("%s\n", a);
}

void
main ()
{
    of();
}
As you will be able to see, variable b overflows into variable a.