This commit is contained in:
ranwenjie
2021-08-17 17:39:37 +08:00
parent 136b59671d
commit 1841228814
57 changed files with 15 additions and 21 deletions
+38
View File
@@ -0,0 +1,38 @@
// FROM:http://www.gowrikumar.com/c/
#include <stdlib.h>
#include <stdio.h>
void Error(char* s)
{
printf(s);
return;
}
int main()
{
int *p;
p = malloc(sizeof(int));
if(p == NULL)
{
Error("Could not allocate the memory\n");
Error("Quitting....\n");
exit(1);
}
else
{
/*some stuff to use p*/
Error("Could not allocate the memory\n");
Error("Quitting....\n");
Error(5);
}
return 0;
}
/*
潜在的问题是:
Error函数中,如果输入的参数不是字符串,比如传一个整数5,5被转成一个内存地址,printf这时候访问就会出问题了。
$1 = 0x5 <error: Cannot access memory at address 0x5>
*/