简体   繁体   中英

Why does initializing a string in a function doesn't work like int while debugging

So I tried debugging some simple C programs today ;

First one being

int main(){

 int a ,b ;
 return 0 ;

}

Which when de-compiled gave me

  push        ebp  
  mov         ebp,esp  
  sub         esp,008h 

because I need to have 8 bytes to store a and b in the current stack frame since they are local variable !

But when I try the same with Strings say

int main() {

    char greeting[12] = "Pwnit2Ownit";
    return 0;
}

Which when de-compiled gave me

 push        ebp  
  mov         ebp,esp  
  sub         esp,0DCh 

0DCh is 220 , But since the string is only 12 bytes long shouldn't the

sub esp,0DCh

be

sub esp,00ch

instead ?

And can anyone share some links on how the strings are stored in the memory and accessed later via assembly [preferebly instruction] , like hows the string greetings stored in memory if it's length is large since we can't store all in the stack itself

As @user3386109 pointed out , The issue is to prevent overflow the default security check in visual studio is enabled , and it provides extra space in order to prevent overflows , so turning it off , made the compiler allocate only 12 bytes :D

To turn this security measure ( Buffer Security Checks GS) off Project settings -> C/C++ -> Code generation -> security check = disable GS

Some post related to GS

http://preshing.com/20110807/the-cost-of-buffer-security-checks-in-visual-c/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM