Skip to content

Commit

Permalink
Only validate non variadic arg slice length
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRPorter committed Jun 10, 2024
1 parent b9ff469 commit 0fe1da0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (g *generator) generateOngoingVerificationGetAllCapturedArguments(ongoingVe
g.p("func (c *%v%v) GetAllCapturedArguments() (%v) {", ongoingVerificationStructName, typeParamNames, strings.Join(argsAsArray, ", "))
if numArgs > 0 {
g.p("_params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)")
g.p("if len(_params) > 0 && len(_params) == %v {", numArgs)
g.p("if len(_params) > 0 {")
for i, argType := range argTypes {
if isVariadic && i == numArgs-1 {
variadicBasicType := strings.Replace(argType, "[]", "", 1)
Expand All @@ -366,10 +366,13 @@ func (g *generator) generateOngoingVerificationGetAllCapturedArguments(ongoingVe
p("}")
break
} else {
// explicitly validate the length of the params slice to avoid out of bounds code smells
g.p("if %v < len(_params) {", i)
g.p("_param%v = make([]%v, len(c.methodInvocations))", i, argType)
g.p("for u, param := range _params[%v] {", i)
g.p("_param%v[u]=param.(%v)", i, argType)
g.p("}")
g.p("}")
}
}
g.p("}")
Expand Down

0 comments on commit 0fe1da0

Please sign in to comment.