Skip to content

Instantly share code, notes, and snippets.

@sw17ch
Created August 16, 2012 20:40
Show Gist options
  • Save sw17ch/3373458 to your computer and use it in GitHub Desktop.
Save sw17ch/3373458 to your computer and use it in GitHub Desktop.
#include <stdio.h>
typedef struct {} a;
typedef struct { a a1; a a2; } b;
int main(int argc, char * argv[])
{
a as[999999];
printf("%d\n", sizeof(b) == sizeof(a));
printf("%zu\n", sizeof(as));
int i;
for(i = 0; i < sizeof(as) / sizeof(as[0]); i++)
{
puts("wat");
}
return 0;
}
/* $ gcc wat.c -O0 -o wat_
* $ ./wat_
* 1
* 0
* wat
*/
Copy link

ghost commented Aug 16, 2012

0xdc(%rbp) is the loop counter, temporarily stashed in %rax / %eax
%ecx is the loop limit, set to zero at ..ebe
branch enters at ..ef7 and loop body at ..edf
cmpq at ..efd sets CF 0 and ZF 0, jb at ..f00 should NOT branch. does this particular compilation emit the "wat"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment