On a system where sizeof(int) is 4 bytes, a points to the start of a successful 44-byte allocation. Memcheck reports an invalid read of size 4 at an address 8 bytes after that block's exclusive end boundary. Assume the read is exactly a[i], using zero-based indexing and an unchanged base pointer. What is i? Answer as an integer to zero decimal places; the index has no units.
Unlock full course notes by signing up
Quantify a leak summary
At normal program exit, a Memcheck leak summary for a C data importer contains the four categories below. There are no suppressed blocks or additional categories. Calculate the combined definitely and indirectly lost memory in bytes, to zero decimal places. Then calculate that combined amount as a percentage of all bytes remaining allocated in the table, to one decimal place.
Classify blocks by reachability at exit
A C program is run with valgrind --leak-check=full. When main returns, the heap and the program's pointers are in this state:
A global variable cache holds the start address of a 64-byte block.
A function load_list built a linked list of three 24-byte nodes and returned without freeing them. Its local head pointer is gone, and no pointer to the first node remains anywhere in memory. The first node's next field holds the start address of the second node, and the second node's next holds the start address of the third.
Separate lifetime repairs from clean-run claims
A single-threaded C program executes the following fragment. Assume the required declarations are present, allocation succeeds, and sizeof(int) is 4 bytes.
Memcheck reports an invalid read of size 4 inside the 12-byte block that was freed by free(p). A separate global cache is reported as 64 bytes still reachable. After a proposed repair, the original input produces no reported errors. Which statements are supported? Select all that apply.
Predict stops from ignore counts and conditions
A program compiled with gcc -g -O0 contains this loop, with total declared and set to zero just before it:
In GDB you enter break 18, which creates breakpoint 1, then ignore 1 120, then run. When the program stops, you print i and total. You then enter condition 1 i % 50 == 0 followed by continue, and when the program stops again you print i and total once more.
Give the value of i and the value of total at each of the two stops, each as an integer.