void command ( const char *args ) {
char buf[MAX_BUFFER] = "\0\0\0\0"; /* Use 4 bytes for 32-bit platforms, 8 bytes for 64-bit platforms */
…
}
(gdb) list
1 void command( args )
2 {
3 char buf[140];
4 }
…
(gdb) disass command
Dump of assembler code for function command:
0x00000001004010d0 <+0>: push %rbp
0x00000001004010d1 <+1>: mov %rsp,%rbp
0x00000001004010d4 <+4>: sub $0x90,%rsp
0x00000001004010db <+11>: mov %ecx,0x10(%rbp)
0x00000001004010de <+14>: add $0x90,%rsp
0x00000001004010e5 <+21>: pop %rbp
0x00000001004010e6 <+22>: retq
End of assembler dump.
When I run the "command" twice, buf is holding it's contents from the previous run through. I was under the impression that any memory set up during the method in a standard declaration like this was cleared when the method was done running. It's acting like a static variable. I'm a little confused, but maybe I misunderstood it to start.
Obviously, I can just memset it at the start of the method but I didn't think I had to on a non-static.