int i;
int *buf;
buf = NULL;
buf = (int *)malloc(100);

for(i = 0;i < 100;i++){
buf[i] = i;
 }

↑これが動いちゃって凄く怖くないですか?