libconfig_format_bin: fix on 32-bit systems#260
Merged
Conversation
Before the change conversion of bin produced wrong
leading zeros and failed test son `i686-linux` as:
[TEST] BinaryAndHex
files "temp.cfg" and "./testdata/binhex.cfg" differ starting at line 5, char 12
tests.c:55: failed assert: ("temp.cfg") ["temp.cfg"] ==txtfile (output_file) ["./testdata/binhex.cfg"]
[FAIL] BinaryAndHex
If fails because the output contains extra leading zeros:
--- ./tests/temp.cfg 2025-05-01 19:33:38.094444650 +0100
+++ ./tests/testdata/binhex.cfg 2025-05-01 14:08:07.152539477 +0100
@@ -2,6 +2,6 @@
regular_bigint = 10000000000L;
hex_int = 0x20;
hex_bigint = 0x1FFFFFFFFL;
-bin_int = 0b000000000000000000000000000000001111;
-bin_bigint = 0b00000000000000000000000000000000100001000010000010000100001L;
-mixed = [ 1, 0x2, 0b0000000000000000000000000000000011 ];
+bin_int = 0b1111;
+bin_bigint = 0b100001000010000010000100001L;
+mixed = [ 1, 0x2, 0b11 ];
This happens because used `int __builtin_clzl (unsigned long)` operates
on 32-bit `long` values.
The fix uses `int __builtin_clzll (unsigned long long)` to fit in 64-bit
values.
Closes: #259
Owner
|
Thank you for the fix! |
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.
Before the change conversion of bin produced wrong leading zeros and failed test son
i686-linuxas:If fails because the output contains extra leading zeros:
This happens because used
int __builtin_clzl (unsigned long)operates on 32-bitlongvalues.The fix uses
int __builtin_clzll (unsigned long long)to fit in 64-bit values.Closes: #259