CodeQL library for Go
codeql/go-all 2.1.4-dev (changelog, source)
Search

Member predicate UpperBoundCheckGuard::isBoundFor

Holds if this upper bound check should stop flow for a flow state with bit size bitSize and architecture bit size architectureBitSize.

A flow state has bit size bitSize if that is the smallest valid bit size b such that the maximum value that could get to that point is less than or equal to 2^(b) - 1. So the flow should be stopped if there is a valid bit size b which is less than bitSize such that the maximum value that could get to that point is than or equal to 2^(b) - 1. In this case, the upper bound check is a barrier guard, because the flow should have bit size equal to the smallest such b instead of bitSize.

The argument architectureBitSize is only used if the constant operand is math.MaxInt or math.MaxUint.

Note that we have to use floats here because integers in CodeQL are represented by 32-bit signed integers, which cannot represent some of the integer values which we will encounter.

predicate isBoundFor(int bitSize, int architectureBitSize)