This page does not represent the most current semester of this course; it is present merely as an archive.
Question 1
0xF2BFD67B
or one digit off of that0x10044020
or 0xE2BB965B
Question 2
C
and D
Question 3
~(~x | ~y)
or (x ^ y) ^ (x | y)
or any similar working expression!(!x || !y)
)Question 4
?01?????
or ?10?????
)1
Question 5
s = x ^ y
and c = x & y
, or the equivalentQuestion 6
Question 7
B
, F
}Question 8
4
or any expression that evaluates to 4
2
or 8
Example Question 9 solutions
int i=0;
L1:
if (i >= n) goto L2;
printf("Step %d\n", i+1);
i+=1;
goto L1;
L2:
int i=0;
goto L2;
L1:
printf("Step %d\n", i+1);
i+=1;
L2:
if (i < n) goto L1;
Q9 loop-style goto
goto
to that labelgoto
, and no loops, but every goto
is downward not upwardQ9 correct behavior
goto
-using code is functionally like the for
-using code.Question 10
free(old)
after the if
in pop
. No points off for other edits (note: as written, this problem cannot be solved without a use-after-free unless they make other edits).free
before the if
or having the right free
but another one somewhere else or for having the wrong argument to the correct free
.Example correct solutions
f:
cmpq $0, %rsi;
je done;
subq %rsi, %rdi;
movq %rsi, %rax;
movq %rdi, %rsi;
movq %rax, %rdi;
callq f;
retq;
done:
movq %rdi, %rax;
retq
f:
cmpq $0, %rsi;
jne recur;
movq %rdi, %rax;
retq;
recur:
subq %rsi, %rdi;
xchg %rsi, %rdi;
jmp f;
Q11 function
%rdi
, b = %rsi
, and return value = %rax
%rdi
and %rsi
+
or +=
instead of leaq
or addq
retq
Q11 branching
je
/jne
Q11 recursion
callq
and retq
(or jmp
)Question 12
sum
is uninitializedsum
could be anything at allfree
d memory, but mentioning that is not necessary)Q13 description
malloc
s the return valuemalloc
or giving a description of the code instead of its functionQ13 example
list_of_vectors
is [[1, 2, 3], [4, 5, 6]], returns [5, 7, 9]” is incomplete (doesn’t say how to make that array, what the other args are, etc) but sufficient for full credit.list_of_vectors
is [[1, 2, 3], [4, 5, 6]], returns [6, 15].”one correct solution
long int strtol(const char *nptr, char **endptr, int base) {
long ans = 0, neg = 0, overflow = 0;
while (isspace(*nptr)) nptr += 1;
if (*nptr == '-') { neg = 1; nptr += 1; }
else if (*nptr == '+') { nptr += 1; }
for(; *nptr >= '0' && *nptr <= ('0'+base); nptr += 1) {
long next = (ans * base) + (*nptr - '0');
if (next - neg < ans) overflow = 1;
ans = next;
}
if (endptr) *endptr = (char *)nptr;
if (overflow) {
errno = ERANGE;
return neg ? LLONG_MIN : LLONG_MAX;
}
return neg ? -ans : ans;
}
Q14 pre-number handling
Q14 number conversion
Q14 endptr
Q14 overflow
Questions 15 through 17
Function | read |
fread , fgets , or fscanf |
fgetc |
getline |
---|---|---|---|---|
Q15 | A | C | C | C |
Q16 | C | C (fgets : partial for A) |
A | B (partial for C) |
Q17 | B | A | B | A |
If the have a consistent answer set (ACB, CCA, CAB, or CBA) that does not match the function listed, give partial on each.
Question 18
The most correct answer is C
, as technically free
d memory is still on the heap. But we’re accepting B
as correct too for grading.
B
and/or C
B
and/or C
and also A
and/or D
Question 19 (dropped due to overwhelming misunderstanding of question)
C
and E
C
, E
, and other options tooC
and D
E
Note : D
(which implies E
) is not the definition of garbage, it is a definition of unreachable
For both questions, if the fix is correct read the bug description generously.
Question 20
realloc
might return a new pointer (or “heap buffer overflow”)x =
in front of realloc
Question 21
struct p
s as intended (or “heap buffer overflow” or “wrong sizeof
argument”, etc.)size(struct p *)
to size(struct p)
;
on last line).
to ->
”