x.json2: fix decode_number not initializing value to zero#25675
Merged
spytheman merged 2 commits intoNov 6, 2025
Conversation
Fixes issue vlang#25641 where u16 and other integer types were incorrectly decoded from JSON. The bug occurred because decode_number accumulated digits without first initializing the target value to zero. When decoding struct fields, if the struct had a pre-existing value, the decoder would append digits to that value instead of replacing it. For example, decoding 25 into a field that already contained 25 would result in 2525. The fix adds explicit zero initialization at the start of both positive and negative number decoding paths before accumulating digits. Changes: - Initialize *val = 0 before processing positive integers - Initialize *val = 0 before processing negative integers - Add test case to verify the fix and prevent regression
ae2886f to
140b0b7
Compare
Contributor
Author
|
Fixed the formatting issue. The test file has been reformatted with |
spytheman
reviewed
Nov 6, 2025
Contributor
|
Thank you @chethanyadav456 🙇🏻 . |
spytheman
approved these changes
Nov 6, 2025
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.
Fixes issue #25641 where u16 and other integer types were incorrectly decoded from JSON. The bug occurred because decode_number accumulated digits without first initializing the target value to zero.
When decoding struct fields, if the struct had a pre-existing value, the decoder would append digits to that value instead of replacing it. For example, decoding 25 into a field that already contained 25 would result in 2525.
The fix adds explicit zero initialization at the start of both positive and negative number decoding paths before accumulating digits.
Changes: