aboutsummaryrefslogtreecommitdiff
path: root/lib/src/fmt.c
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2021-04-28 23:08:45 +0200
committerjohannst <johannes.stoelp@gmail.com>2021-04-28 23:08:45 +0200
commitd367355eb4c3569d422034b69737d8dc7022e13e (patch)
treef9f6768228235f4712466d65edeb0b745d904833 /lib/src/fmt.c
parentcf97ecd5b52c2f7a8953fd1674742d46fd15418a (diff)
parentfc137e7d0263a0fe908ca1a150e34a9c8b9902d4 (diff)
downloaddynld-d367355eb4c3569d422034b69737d8dc7022e13e.tar.gz
dynld-d367355eb4c3569d422034b69737d8dc7022e13e.zip
Merge branch 'dev04'
Diffstat (limited to 'lib/src/fmt.c')
-rw-r--r--lib/src/fmt.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/src/fmt.c b/lib/src/fmt.c
index be1ca3a..24ddd98 100644
--- a/lib/src/fmt.c
+++ b/lib/src/fmt.c
@@ -11,7 +11,7 @@ static const char* num2dec(char* buf, unsigned long len, unsigned long long num)
}
while (num > 0 && pbuf != buf) {
- char d = (num % 10) + '0';
+ char d = (char)(num % 10) + '0';
*(--pbuf) = d;
num /= 10;
}
@@ -28,7 +28,7 @@ static const char* num2hex(char* buf, unsigned long len, unsigned long long num)
while (num > 0 && pbuf != buf) {
char d = (num & 0xf);
- *(--pbuf) = d + (d > 9 ? 'a' - 10 : '0');
+ *(--pbuf) = (char)(d + (d > 9 ? 'a' - 10 : '0'));
num >>= 4;
}
return pbuf;
@@ -51,7 +51,7 @@ int vfmt(char* buf, unsigned long len, const char* fmt, va_list ap) {
put(*s++); \
}
- char scratch[16];
+ char scratch[32];
int l_cnt = 0;
while (*fmt) {
@@ -73,7 +73,7 @@ int vfmt(char* buf, unsigned long len, const char* fmt, va_list ap) {
val *= -1;
put('-');
}
- const char* ptr = num2dec(scratch, sizeof(scratch), val);
+ const char* ptr = num2dec(scratch, sizeof(scratch), (unsigned long)val);
puts(ptr);
} break;
case 'x': {
@@ -81,6 +81,10 @@ int vfmt(char* buf, unsigned long len, const char* fmt, va_list ap) {
const char* ptr = num2hex(scratch, sizeof(scratch), val);
puts(ptr);
} break;
+ case 'c': {
+ char c = va_arg(ap, int); // By C standard, value passed to varg smaller than `sizeof(int)` will be converted to int.
+ put(c);
+ } break;
case 's': {
const char* ptr = va_arg(ap, const char*);
puts(ptr);