Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ const Value& Value::operator[](int index) const {
void Value::initBasic(ValueType type, bool allocated) {
setType(type);
setIsAllocated(allocated);
value_.uint_ = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Some bytes remain uninitialized

With JSON_NO_INT64, LargestUInt is unsigned int. If that type is four bytes and double is eight, this assignment initializes only half of ValueHolder. The move constructor still swaps the whole union, so it still copies uninitialized bytes in that configuration. Clear the whole value_ storage rather than only value_.uint_.

Knowledge Base Used: Value storage and traversal internals

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

memset(&value_, 0, sizeof(value_)); also works and prevents the warning.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed—memset(&value_, 0, sizeof(value_)); clears the entire union storage, including the bytes left untouched when LargestUInt is narrower than double. That resolves my concern about value_.uint_ = 0 being insufficient under JSON_NO_INT64.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

comments_ = Comments{};
start_ = 0;
limit_ = 0;
Expand Down
Loading