Skip to content

Commit

Permalink
max recursion depth
Browse files Browse the repository at this point in the history
Signed-off-by: czechbol <[email protected]>
  • Loading branch information
czechbol committed Aug 28, 2024
1 parent 9d21571 commit 2babcc4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions analyzers/conversion_overflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,13 @@ func hasExplicitRangeCheck(instr *ssa.Convert, dstType string) bool {
return true
}

// Recursive function to check predecessors
var checkPredecessors func(block *ssa.BasicBlock) bool
checkPredecessors = func(block *ssa.BasicBlock) bool {
// Recursive depth-first search of predecessor blocks of the SSA function to find bounds checks on the value being converted
var checkPredecessors func(block *ssa.BasicBlock, depth int) bool
checkPredecessors = func(block *ssa.BasicBlock, depth int) bool {
if depth > maxDepth {
return false
}

for _, pred := range block.Preds {
minChecked, maxChecked := checkBlockForRangeCheck(pred, instr, dstInt)

Expand All @@ -180,15 +184,15 @@ func hasExplicitRangeCheck(instr *ssa.Convert, dstType string) bool {
if minBoundChecked && maxBoundChecked {
return true
}
if checkPredecessors(pred) {
if checkPredecessors(pred, depth+1) {
return true
}
}
return false
}

// Start checking from the initial block
checkPredecessors(block)
checkPredecessors(block, 0)

if minBoundChecked && maxBoundChecked {
return true
Expand Down

0 comments on commit 2babcc4

Please sign in to comment.