Skip to content

Commit

Permalink
Explicitly validate the len of params to ensure we don't get index ou…
Browse files Browse the repository at this point in the history
…t of bounds
  • Loading branch information
AndrewRPorter authored and petergtz committed Jun 7, 2024
1 parent d5c0135 commit b9ff469
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,17 @@ func (g *generator) generateOngoingVerificationGetCapturedArguments(ongoingVerif
}

func (g *generator) generateOngoingVerificationGetAllCapturedArguments(ongoingVerificationStructName string, typeParamNames string, argTypes []string, isVariadic bool) *generator {
argsAsArray := make([]string, len(argTypes))
numArgs := len(argTypes)
argsAsArray := make([]string, numArgs)
for i, argType := range argTypes {
argsAsArray[i] = fmt.Sprintf("_param%v []%v", i, argType)
}
g.p("func (c *%v%v) GetAllCapturedArguments() (%v) {", ongoingVerificationStructName, typeParamNames, strings.Join(argsAsArray, ", "))
if len(argTypes) > 0 {
if numArgs > 0 {
g.p("_params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)")
g.p("if len(_params) > 0 {")
g.p("if len(_params) > 0 && len(_params) == %v {", numArgs)
for i, argType := range argTypes {
if isVariadic && i == len(argTypes)-1 {
if isVariadic && i == numArgs-1 {
variadicBasicType := strings.Replace(argType, "[]", "", 1)
g.
p("_param%v = make([]%v, len(c.methodInvocations))", i, argType).
Expand Down

0 comments on commit b9ff469

Please sign in to comment.