aboutsummaryrefslogtreecommitdiff
path: root/src/debug.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-07 00:49:55 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-07 00:49:55 +0300
commit03e12129927b0deba537a11bb5575bef93c57d0f (patch)
tree3e2fce59e7c6d604e163236b44f7f96d1c31e279 /src/debug.c
parent3fedbb6e1f849c5e0a4033d68201d60c2fc48121 (diff)
downloadkmi-03e12129927b0deba537a11bb5575bef93c57d0f.tar.gz
kmi-03e12129927b0deba537a11bb5575bef93c57d0f.zip
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.
Diffstat (limited to 'src/debug.c')
-rw-r--r--src/debug.c38
1 files changed, 17 insertions, 21 deletions
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;
}
/**