Skip to content

Commit

Permalink
Fix nil pointer dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswiagarwal committed Aug 14, 2019
1 parent b6ca86b commit 6435a6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions codegen/method.go
Expand Up @@ -802,25 +802,26 @@ func (ms *MethodSpec) setClientRequestHeaderFields(
// Note header values are always string
headerNameValuePair = "headers[%q]= string(r%s)"
} else {
headerNameValuePair = "if r%s != nil {" +
"headers[%q]= string(*r%s)" + "}"
headerNameValuePair = "headers[%q]= string(*r%s)"
}
if len(seenOptStructs) == 0 {
statements.appendf(headerNameValuePair,
headerName, bodyIdentifier,
)
} else {
if len(seenOptStructs) != 0 {
closeFunction := ""
for seenStruct := range seenOptStructs {
if strings.HasPrefix(longFieldName, seenStruct) {
statements.appendf("if r%s != nil {", seenStruct)
closeFunction = closeFunction + "}"
}
}
statements.append(closeFunction)
}
if field.Required {
statements.appendf(headerNameValuePair,
headerName, bodyIdentifier,
)
statements.append(closeFunction)
} else {
statements.appendf("if r%s != nil {", bodyIdentifier)
statements.appendf(headerNameValuePair, headerName, bodyIdentifier)
statements.append("}")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/example-gateway/build/clients/bar/bar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6435a6c

Please sign in to comment.