Language: Go
Label: vulnerable
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 BenchmarkBitfield(t *testing.B) {
	bf := NewBitfield(benchmarkSize)
	t.ResetTimer()
	for i := 0; i < t.N; i++ {
		if bf.Bit(i % benchmarkSize) {
			t.Fatal("bad", i)
		}
		bf.SetBit(i % benchmarkSize)
		bf.UnsetBit(i % benchmarkSize)
		bf.SetBit(i % benchmarkSize)
		bf.UnsetBit(i % benchmarkSize)
		bf.SetBit(i % benchmarkSize)
		bf.UnsetBit(i % benchmarkSize)
		bf.SetBit(i % benchmarkSize)
		if !bf.Bit(i % benchmarkSize) {
			t.Fatal("bad", i)
		}
		bf.UnsetBit(i % benchmarkSize)
		bf.SetBit(i % benchmarkSize)
		bf.UnsetBit(i % benchmarkSize)
		bf.SetBit(i % benchmarkSize)
		bf.UnsetBit(i % benchmarkSize)
		bf.SetBit(i % benchmarkSize)
		bf.UnsetBit(i % benchmarkSize)
		if bf.Bit(i % benchmarkSize) {
			t.Fatal("bad", i)
		}
	}
}