mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-26 21:58:08 +01:00
Fix edge case bug in numlen, dropping use of math.h functions
(Specifically, numlen when called with INT_MIN gave an incorrect result, because abs(INT_MIN) == INT_MIN < 0.)
This commit is contained in:
parent
d7ff776552
commit
c040defd5f
1 changed files with 5 additions and 4 deletions
|
@ -12,11 +12,12 @@ int wrap(int i, int max) {
|
|||
}
|
||||
|
||||
int numlen(int n) {
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
int j = n <= 0 ? 1 : 0;
|
||||
while (n) {
|
||||
j++;
|
||||
n /= 10;
|
||||
}
|
||||
// Account for the '-' in negative numbers.
|
||||
return log10(abs(n)) + (n > 0 ? 1 : 2);
|
||||
return j;
|
||||
}
|
||||
|
||||
uint32_t parse_color(const char *color) {
|
||||
|
|
Loading…
Reference in a new issue