gcc -o stdlib.h语法错误c攻击剥削艺术

我正在使用VM(虚拟机箱)运行其附带的LiveCD(Ubuntu 7.04),从第二版Jon Erickson的“黑客:剥削艺术”开始。 在第0x272节“使用堆”中,作者使用第77-79页上的示例解释了malloc()和free()函数。

heap_example.c的代码如下:

#include  #include  #include  int main(int argc,char *argv[]){ char *char_ptr; int *int_ptr; int mem_size; if(argc '%s'\n",char_ptr,char_ptr); printf("\t[+]allocating 12 bytes of memory on the heap for int_ptr\n"); int_ptr = (int *)malloc(12); if(int_ptr == NULL){ fprintf(stderr,"Error:could not allocate heap memory.\n"); exit(-1); } *int_ptr = 31337; printf("int_ptr (%p)--> %d\n",int_ptr,*int_ptr); printf("\t[-]freeing char_ptr's heap memory...\n"); free(char_ptr); printf("\t[+]allocating another 15 bytes for char_ptr\n"); char_ptr = (char*)malloc(15); if(char_ptr == NULL){ fprintf(stderr,"Error:could not allocate heap memory.\n"); exit(-1); } strcpy(char_ptr,"new memory"); printf("char_ptr (%p)-->'%s'\n",char_ptr,char_ptr); printf("\t[-]freeing int_ptr's heap memory...\n"); free(int_ptr); printf("\t[-]freeing char_ptr's heap memory...\n"); free(char_ptr); } 

但是,当我在书中输入以下说明到我的终端窗口时:

 reader@hacking:~/booksrc $ gcc -o heap_example heap_example.c 

它在我的stdlib.h中吐出有关语法错误的以下错误消息

 In file included from heap_example.c:2: /usr/include/stdlib.h:469: error: syntax error before "int32_t" /usr/include/stdlib.h:471: error: syntax error before '*' token /usr/include/stdlib.h:475: error: syntax error before '*' token /usr/include/stdlib.h:476: error: syntax error before '}' token /usr/include/stdlib.h:479: error: syntax error before "int32_t" 

这是我的stdlib.h中出现错误的地方(第467 – 479行)

 struct random_data { int32_t *fptr; /* Front pointer. */ int32_t *rptr; /* Rear pointer. */ int32_t *state; /* Array of state values. */ int rand_type; /* Type of random number generator. */ int rand_deg; /* Degree of random number generator. */ int rand_sep; /* Distance between front and rear. */ int32_t *end_ptr; /* Pointer behind state table. */ }; extern int random_r (struct random_data *__restrict __buf, int32_t *__restrict __result) __THROW __nonnull ((1, 2)); 

然后,当我尝试运行它:

 reader@hacking:~/booksrc $ ./heap_example 

我明白了:

 bash: ./heap_example: No such file or directory 

我相信heap_example.c是本书中第一个包含stdlib.h的文件(所有前面的例子只使用了stdio.h,所以我没有问题)。

将更改stdlib.h文件修复此问题? 如果是这样,我该如何纠正这些错误? 我想我应该尽快解决这个问题,因为本书中的其余代码示例可能会开始包含stdlib.h

谢谢!