





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






























Introduction to Computer Systems
class16.ppt
left to right
(type)
sizeof
right to left
left to right
left to right
left to right
left to right
left to right
left to right
left to right
left to right
left to right
left to right
right to left
right to left
left to right
class16.ppt
The classic scanf bug scanf(“%d”, val);
for (i=0; i<N; i++) {p = malloc(N*sizeof(int)); int **p; p[i] =
(^) malloc(M*sizeof(int));
Off-by-one
for (i=0; i<=N; i++) {p = malloc(N*sizeof(int *)); int **p; p[i] =
(^) malloc(M*sizeof(int));
strcpy(t, s);char s[8] = “1234567”; char t[7];
gets(s);int i; char s[8];
/* reads “123456789” from stdin */
(^) int val) {
while (*p && *p !=
(^) val)
p += (^) sizeof(int);
Forgetting that local variables disappear when a
function returns
int *foo () { return &val;int val;
Evil!
for (i=0; i<M; i++)y = malloc(Msizeof(int));...free(x);
slow, long-term killer!
foo() { int (^) x = malloc(Nsizeof(int));
return;...
class16.ppt