Bug Four Hint

This is a big hint.

If the following code is used as the main function body, then things work fine until the second call to unpack, at which point we get a Bus error. Why?


int main() {

	char s1[128];
	char s2[128];
	int j, k;

	strcpy(s1, "Ayo");
	strcpy(s2, "Hi");
	j = 10;
	k = 20;

	void *vp1, *vp2;
	pack(&vp1, s1, j);
	pack(&vp2, s2, k);

	// this works fine
	char *t;
	int i;
	unpack(vp1, &t, i);
	printf("Output: t=%s i=%d\n", t, i);

	// this does not
	unpack(vp2, &t, i);
	printf("Output: t=%s i=%d\n", t, i);

	return 0;

}


Answer
Bugs