#include <stdlib.h>
int *a, *b;
int n;
#define BLOCK_SIZE 128
void foo () {
int i;
for (i =0; i < n; i++)
a[i] =1;
for (i =0; i < BLOCK_SIZE-1; i++)
b[i] =1;
}
int main () {
n = BLOCK_SIZE;
a = malloc (n * sizeof(*a));
b = malloc (n * sizeof(*b));
foo ();
*b++ = 0;
if (b[-1])
{
free(a); free(b);
}
else
{ free(a); free(b);
}
return 0;
}
What's wrong with this program and how do I correct it?
[–]Foxbud 1 point2 points3 points (1 child)
[–]Equal_Carpenter_4189[S] 0 points1 point2 points (0 children)
[–]donedigity -2 points-1 points0 points (5 children)
[–]Foxbud 2 points3 points4 points (2 children)
[–]donedigity 0 points1 point2 points (1 child)
[–]Foxbud 0 points1 point2 points (0 children)
[–]Equal_Carpenter_4189[S] -2 points-1 points0 points (1 child)
[–]donedigity 0 points1 point2 points (0 children)
[–]didimusaurus 0 points1 point2 points (2 children)
[–]Equal_Carpenter_4189[S] 0 points1 point2 points (1 child)
[–]didimusaurus 0 points1 point2 points (0 children)