Language: Go
Label: safe
CWE: CWE-1284 \u2014 Improper Validation of Specified Quantity in Input
The product receives input that is expected to specify a quantity (such as size or length), but it does not validate or incorrectly validates that the quantity has the required properties.

Code:
func BenchmarkOnes(b *testing.B) {
	bf, err := NewBitfield(benchmarkSize)
	assertNoError(b, err)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		for j := 0; j*4 < benchmarkSize; j++ {
			if bf.Ones() != j {
				b.Fatal("bad", i)
			}
			bf.SetBit(j * 4)
		}
		for j := 0; j*4 < benchmarkSize; j++ {
			bf.UnsetBit(j * 4)
		}
	}
}