From 8438d9fc71eaf7ca3192cf8fb63bfaf1df441dd7 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Thu, 19 Sep 2024 11:57:26 -0700 Subject: [PATCH] Prevent panic: unexpected constant value: --- 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 d8efd50450..bebe9b8340 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)