fix(proto): encode nil *uint8 as "0" like other numeric pointers#3869
Open
sueun-dev wants to merge 2 commits into
Open
fix(proto): encode nil *uint8 as "0" like other numeric pointers#3869sueun-dev wants to merge 2 commits into
sueun-dev wants to merge 2 commits into
Conversation
WriteArg encodes a nil pointer to a numeric type as its zero value: every nil *int*/*uint*/*float*/*bool returns "0". The *uint8 case instead returned an empty string, which is also inconsistent with its own non-nil path that writes the number via w.uint. Encode nil *uint8 as "0" and update the table test assertion.
Member
|
@sueun-dev this makes sense based on the rest uint handling, but let me verify that there is no case where we would like to keep nil as |
ofekshenawa
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WriteArgencodes a nil pointer to a numeric type as its zero value. Every nil*int,*int8,*int16,*int32,*int64,*uint,*uint16,*uint32,*uint64,*float32,*float64,*booland*time.Durationencodes as"0". The*uint8case returned an empty string instead.It is also inconsistent with the non-nil
*uint8path, which writes the number throughw.uint. The table test already assertsuint8(10)and*uint8(10)both encode as"10", souint8is treated as a number here, not a byte.In practice
var p *uint8; rdb.Set(ctx, key, p, 0)sent""while every other nil numeric pointer sent"0".The empty-string branch came in with the other nil-pointer guards in #3271; it looks like the one case that was missed rather than intended behavior.
Note this is a wire-output change for the nil
*uint8case: it now sends"0"($1\r\n0\r\n) instead of an empty bulk string ($0\r\n\r\n).Changed the nil branch to
w.uint(0)and updated the(*uint8)(nil)expectation in the writer table test.Tested:
Note
Low Risk
Single-branch serialization fix in the proto writer with a narrow wire-output change for nil
*uint8only.Overview
WriteArgnow encodes a nil*uint8as"0"viaw.uint(0), matching every other nil numeric pointer type instead of an empty bulk string.This is a wire-format change for that case only: Redis commands that pass a nil
*uint8(e.g.Setwith a nil pointer value) will send$1\r\n0\r\ninstead of$0\r\n\r\n. The writer table test expectation for(*uint8)(nil)was updated accordingly.Reviewed by Cursor Bugbot for commit 081addb. Bugbot is set up for automated code reviews on this repo. Configure here.