1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-25 01:05:21 +03:00

[BITARRAY] Bounds check in the first iteration in bitArrayFindFirstSet() (#5707)

We already had bounds checking for the 2nd and subsequent 32 bit
blocks, but since the first block was handled separately (due to the
masking needed if it doesn't fall on a 32 bit boundary) it skipped
the check. With this change, any start bit >= the number of bits
in the array will return -1.
This commit is contained in:
Alberto García Hierro 2020-05-16 16:38:31 +01:00 committed by GitHub
parent 3cbf830e04
commit 7f1a7d5a0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 8 deletions

View file

@ -83,3 +83,14 @@ TEST(BitArrayTest, TestSetClrAll)
EXPECT_EQ(ii, BITARRAY_FIND_FIRST_SET(p, ii));
}
}
TEST(BitArrayTest, TestOutOfBounds)
{
const int bits = 32 * 4;
BITARRAY_DECLARE(p, bits);
BITARRAY_CLR_ALL(p);
EXPECT_EQ(-1, BITARRAY_FIND_FIRST_SET(p, 0));
EXPECT_EQ(-1, BITARRAY_FIND_FIRST_SET(p, bits));
EXPECT_EQ(-1, BITARRAY_FIND_FIRST_SET(p, bits + 1));
}