Skip to content

Prevent decimal display widgets from getting truncated

Jordan Christiansen requested to merge xordspar0/ghex:fix-decimal-display into master

We calculate the number of allowed characters in the decimal widgets by converting a large number to a string representing the decimal value and counting the number of characters in that string. Previously we used 0xfbfbfbfbfbfbfbfb as the "large number" for all types of ints: signed/unsigned 8-bit all the way to signed/unsigned 64-bit.

This number is not long enough for some types of integers. For example, for a signed 8-bit number, 0xfb is -5, which is only 2 characters. This causes all uint8 numbers to get truncated to the first 2 characters (-128 will get truncated to -1).

Now we take the longest unsigned number (0xff..ff) and the longest signed number (0x80..80) and use the longer of the two. It would be better to use 0x80..00 for signed numbers, but that would require a different number for every type of int, and we don't know the width of the integer we're working with in this context. In any case, 0x80..80 is just as many characters as 0x80..00 in decimal, so it should be fine.

Merge request reports