Skip to content

Commit

Permalink
Fix puthex_unsigned when int is wider than 32 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenthuberdeau committed Feb 16, 2025
1 parent 289959c commit 50878b0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ text concatenate_strings_with(text t1, text t2, text sep) {
// Output unsigned integer in hex
void puthex_unsigned(int n) {
// Because n is signed, we clear the upper bits after shifting in case n was negative
if (n & ~15) puthex_unsigned((n >> 4) & 0x0fffffff);
if ((n >> 4) & 0x0fffffff) puthex_unsigned((n >> 4) & 0x0fffffff);
putchar("0123456789abcdef"[n & 15]);
}

void putoct_unsigned(int n) {
// Because n is signed, we clear the upper bits after shifting in case n was negative
if (n & ~7) putoct_unsigned((n >> 3) & 0x1fffffff);
if ((n >> 3) & 0x1fffffff) putoct_unsigned((n >> 3) & 0x1fffffff);
putchar('0' + (n & 7));
}

Expand Down

0 comments on commit 50878b0

Please sign in to comment.