From 03e12129927b0deba537a11bb5575bef93c57d0f Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 7 Jul 2024 00:49:55 +0300 Subject: fixed crash with dbg_fdt() + Apparently dbg_fdt() itself wasn't buggy, but for whatever reason GCC produced an absolute load to the prefix string in __print_prefix() which caused all the issues. Unclear why, seems like a compiler bug. This commit is more of a workaround, I'd still like to investigate this further. --- src/debug.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'src/debug.c') diff --git a/src/debug.c b/src/debug.c index fcec537..15640b4 100644 --- a/src/debug.c +++ b/src/debug.c @@ -364,6 +364,16 @@ static size_t __integral_val(ssize_t value, size_t base, size_t flags, return ret + 1; } +static size_t __puts(const char *s) +{ + size_t i = 0; + while (s[i]) { + __putchar(s[i++]); + } + + return i; +} + /** * Print prefix corresponding to \c base. * @@ -372,28 +382,14 @@ static size_t __integral_val(ssize_t value, size_t base, size_t flags, */ static size_t __print_prefix(size_t base) { - size_t i = 0; - - const char *hex = "0x"; - const char *oct = "0"; - const char *bin = "0b"; - const char *empty = ""; - - const char *prefix; - - if (base == 16) - prefix = hex; - else if (base == 8) - prefix = oct; - else if (base == 2) - prefix = bin; - else - prefix = empty; - - for (; *prefix; ++i) - __putchar(*prefix++); + switch (base) { + case 16: return __puts("0x"); + case 8: return __puts("0"); + case 2: return __puts("0b"); + default: + } - return i; + return 0; } /** -- cgit v1.3