标签:运算 har amp 程序 malloc 间接 get tac 数组
int main()
{
int val;
scanf("%d", val); // Error!
scanf("%d", &val); // Ok!
return 0;
}
int main()
{
int n = 10;
int* y = (int*) malloc(n * sizeof(int));
for (int i = 0; i < n; i++)
{
y[i] += i; // Error! y[i] != 0. Let y[i] = 0 or use calloc().
}
return 0;
}
int main()
{
char buf[64];
gets(buf); // Error! Use fgets().
return 0;
}
int main()
{
int n = 10;
int m = 5;
// Error! Should be sizeof(int*), sizeof(int*) could be 4 bytes or 8 bytes.
int** A = (int**) malloc(n * sizeof(int));
for (int i = 0; i < n; i++)
{
A[i] = (int*) malloc(m * sizeof(int));
}
return 0;
}
int main()
{
int a[10];
for (int i = 0; i <= 10; i++) // Error! Should be i < 10.
{
a[i] = i;
}
return 0;
}
int main()
{
int a[1] = 10;
int* p = a[0];
*p--; // Error! Should be (*p)--.
cout << *p << endl;
return 0;
}
int* search(int *p, int val)
{
while (*p && *p != val)
p += sizeof(int); // Error! Should be p++.
return p;
}
int *stackref()
{
int val;
return &val; // Error! Returned a pointer to local variable.
}
int main()
{
int* x = (int*) malloc(100);
free(x);
x[0]; // Error! x[0] is in a free block.
return 0;
}
void leak(int n)
{
int* x = (int*) malloc(n * sizeof(int));
return; // Error! Should use free();
}
标签:运算 har amp 程序 malloc 间接 get tac 数组
原文地址:https://www.cnblogs.com/yiluyisha/p/9226578.html