Skip to content

Commit

Permalink
pw_grpc: Fix some minor bugs
Browse files Browse the repository at this point in the history
These were uncovered by static checkers on internal copybara import.

1. Two instances of Printf with a single argument
   (https://staticcheck.dev/docs/checks#SA1006).
1. One instance of ineffective break statement
   (https://staticcheck.dev/docs/checks#SA4011).
1. One Sprintf with missing argument.

Change-Id: If6795fad5f54e783e785f5a6ef897584dfc67946
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/191831
Pigweed-Auto-Submit: Ted Pudlik <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Austin Foxley <[email protected]>
  • Loading branch information
tpudlik authored and CQ Bot Account committed Feb 12, 2024
1 parent 460f429 commit 6b4f24a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pw_grpc/gen/hpack_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ func updateTree(out int, code string) {
// End of the code: create a leaf node.
// Each code should lead to a unique leaf node.
if curr.child[bit] != nil {
panic(fmt.Sprintf("code for byte %v reached a duplicate leaf node"))
panic(fmt.Sprintf("code for byte %v reached a duplicate leaf node", out))
}

switch {
case out == EOS:
curr.child[bit] = &Node{t: EOSNode}
break
case out < 32 || 127 < out:
// Unprintable characters are allowed by the Huffman code but not in gRPC.
// See: https://github.com/grpc/grpc/blob/v1.60.x/doc/PROTOCOL-HTTP2.md#requests.
Expand Down Expand Up @@ -287,15 +286,15 @@ func printStaticResponses() {
respHeaderFields := buildResponseHeaderFields()
fmt.Printf(responseHeaderFieldsPrefix, len(respHeaderFields))
fmt.Printf(" %s", fmtBytes(respHeaderFields))
fmt.Printf(responseHeaderFieldsSuffix)
fmt.Printf("%s", responseHeaderFieldsSuffix)

maxLen := len(buildResponseTrailerFields(maxStatusCode))
fmt.Printf(responseTrailerFieldsPrefix, maxLen, maxStatusCode+1)
for code := 0; code <= maxStatusCode; code++ {
payload := buildResponseTrailerFields(code)
fmt.Printf(" {.size=%d, .bytes={%s}},\n", len(payload), fmtBytes(payload))
}
fmt.Printf(responseTrailerFieldsSuffix)
fmt.Printf("%s", responseTrailerFieldsSuffix)
}

func fmtBytes(bytes []byte) string {
Expand Down

0 comments on commit 6b4f24a

Please sign in to comment.