From 1d2a6f21294f8390b683e4e097cb49210ed832d1 Mon Sep 17 00:00:00 2001 From: johannst Date: Fri, 26 Mar 2021 23:17:46 +0100 Subject: Added dyn allocator + syscall wrappers + minor fixes. --- lib/src/fmt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/src/fmt.c') diff --git a/lib/src/fmt.c b/lib/src/fmt.c index be1ca3a..b0840de 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; @@ -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': { -- cgit v1.2.3 From 1bcaa7aceefad99c7bda9cb7bf6fcc5b48b53a75 Mon Sep 17 00:00:00 2001 From: johannst Date: Sat, 17 Apr 2021 23:41:52 +0200 Subject: fmt: add support for %c --- lib/src/fmt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/src/fmt.c') diff --git a/lib/src/fmt.c b/lib/src/fmt.c index b0840de..56d95ed 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 = (char)(num % 10) + '0'; + char d = (char)(num % 10) + '0'; *(--pbuf) = d; num /= 10; } @@ -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); -- cgit v1.2.3 From 3155439c1a96f1964aaee799b008331d0b362db3 Mon Sep 17 00:00:00 2001 From: johannst Date: Mon, 19 Apr 2021 21:50:29 +0200 Subject: added tests for fmt() char, long nums --- lib/src/fmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/src/fmt.c') diff --git a/lib/src/fmt.c b/lib/src/fmt.c index 56d95ed..24ddd98 100644 --- a/lib/src/fmt.c +++ b/lib/src/fmt.c @@ -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) { -- cgit v1.2.3