From 1d23143bee7e7e4862d955def8f8bb389fd8b456 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Fri, 20 Sep 2024 01:58:58 -0700 Subject: [PATCH] Prevent panic: unexpected constant value: (#1232) --- analyzers/conversion_overflow.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/analyzers/conversion_overflow.go b/analyzers/conversion_overflow.go index d8efd50..bebe9b8 100644 --- a/analyzers/conversion_overflow.go +++ b/analyzers/conversion_overflow.go @@ -360,7 +360,11 @@ func updateResultFromBinOp(result *rangeResult, binOp *ssa.BinOp, instr *ssa.Con if !ok { return } - + // TODO: constVal.Value nil check avoids #1229 panic but seems to be hiding a bug in the code above or in x/tools/go/ssa. + if constVal.Value == nil { + // log.Fatalf("[gosec] constVal.Value is nil flipped=%t, constVal=%#v, binOp=%#v", operandsFlipped, constVal, binOp) + return + } switch binOp.Op { case token.LEQ, token.LSS: updateMinMaxForLessOrEqual(result, constVal, binOp.Op, operandsFlipped, successPathConvert)