mirror of
https://github.com/opencv/opencv.git
synced 2025-06-27 15:01:50 +08:00
Prevent signed integer overflow in LshTable
This change keeps everything as size_t and the expression is valid because maxk_block > 0 in hte loop.
This commit is contained in:
parent
ba28b7d6df
commit
7e3f6875c1
@ -424,7 +424,7 @@ inline size_t LshTable<unsigned char>::getKey(const unsigned char* feature) cons
|
|||||||
size_t mask_block = mask_[i / sizeof(size_t)];
|
size_t mask_block = mask_[i / sizeof(size_t)];
|
||||||
while (mask_block) {
|
while (mask_block) {
|
||||||
// Get the lowest set bit in the mask block
|
// Get the lowest set bit in the mask block
|
||||||
size_t lowest_bit = mask_block & (-(ptrdiff_t)mask_block);
|
size_t lowest_bit = mask_block & ~(mask_block - 1);
|
||||||
// Add it to the current subsignature if necessary
|
// Add it to the current subsignature if necessary
|
||||||
subsignature += (feature_block & lowest_bit) ? bit_index : 0;
|
subsignature += (feature_block & lowest_bit) ? bit_index : 0;
|
||||||
// Reset the bit in the mask block
|
// Reset the bit in the mask block
|
||||||
|
Loading…
Reference in New Issue
Block a user