Skip to content

Correct the behaviors of WriteBuffer#2346

Open
EstherWx wants to merge 1 commit intoTencent:masterfrom
EstherWx:fix-cpp-warn
Open

Correct the behaviors of WriteBuffer#2346
EstherWx wants to merge 1 commit intoTencent:masterfrom
EstherWx:fix-cpp-warn

Conversation

@EstherWx
Copy link
Contributor

@EstherWx EstherWx commented Jun 27, 2025

WriteBuffer attempt to dereference a pointer without any check. Adds a safeguard to prevent dereferencing a null pointer to fix it and nullPointer warning detected by cppcheck.

Besides, WriteBuffer always does hashing and returns true. According to the reference of FNV-1a for Hash algorithm, the original code uses a while loop to iterate over the buffer, checking that the current position is less than the end. WriteBuffer should not do hashing when the length is 0.

@tencent-adm
Copy link
Member

tencent-adm commented Jun 27, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

@admorgan admorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second commit fixes a bug introduced in the first. It would be better to combine them into one commit.

WriteBuffer attempt to dereference a pointer without any check. Adds a
safeguard to prevent dereferencing a null pointer to fix it and
nullPointer warning detected by cppcheck.

Besides, WriteBuffer always does hashing and returns true. According to
the reference of FNV-1a for Hash algorithm, the original code uses a
while loop to iterate over the buffer, checking that the current
position is less than the end. WriteBuffer should not do hashing when
the length is 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants