Skip to Content
marmot

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

The mistake
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
}
Fixed
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.

On this page

Was this page helpful?

Report an issueOpen issues