M0120 possible run-time panic
marmot verify found an operation that can panic at run time (index or slice out of range, nil dereference, division by zero, ...).
A manifest finding is a panic that a guard in the code fails to exclude: the code tests the quantity, but with a weaker bound than the operation needs, so the input the message names passes the guard and panics. A latent finding is a panic for some inputs of the function, a precondition its callers must meet; latent findings are notes and are shown with -latent. The verify object in JSON has the obligation, the condition, the status and the assumptions the result depends on.
The mistake and the fix
func Header(b []byte) (byte, uint16) {
if len(b) < 2 {
return 0, 0
}
return b[0], uint16(b[1])<<8 | uint16(b[2]) // len(b) == 2 panics
}func Header(b []byte) (byte, uint16) {
if len(b) < 3 {
return 0, 0
}
return b[0], uint16(b[1])<<8 | uint16(b[2])
}The fix
Tighten the guard to the bound the operation needs, or check the input before the operation. A fix that returns early silences the panic but can change behavior: the program's tests decide.
See also all error codes and marmot explain.
M0111 heap allocation
marmot build -allocs lists where the program allocates on the heap and why the object could not live in the frame: it is returned, stored in memory that outlives the function or in a global, passed to a call that may keep it, captured by an escaping closure, converted to an interface, kept across loop iterations, or too large for the frame.
Design
How the compiler and the runtime are put together.