diff --git a/abstract-machine/klib/include/klib.h b/abstract-machine/klib/include/klib.h index ecb24c8..33e1a78 100644 --- a/abstract-machine/klib/include/klib.h +++ b/abstract-machine/klib/include/klib.h @@ -9,7 +9,7 @@ extern "C" { #endif -//#define __NATIVE_USE_KLIB__ +// #define __NATIVE_USE_KLIB__ // string.h void *memset (void *s, int c, size_t n); diff --git a/abstract-machine/klib/src/printf.c b/abstract-machine/klib/src/printf.c index d79f9d9..a4969b4 100644 --- a/abstract-machine/klib/src/printf.c +++ b/abstract-machine/klib/src/printf.c @@ -29,16 +29,15 @@ int num_to_ascii(int num, int power, int size, char *buf) { return ret; } -static inline int print_fmt(char **out, int n, const char** fmt, void* _ap) { - va_list ap = *(va_list*)_ap; +static inline int print_fmt(char **out, int n, const char** fmt, va_list (*ap)) { int ret = 0; switch (**fmt) { case 'd': - ret = num_to_ascii(va_arg(ap, int), 10, n, *out); + ret = num_to_ascii(va_arg(*ap, int), 10, n, *out); (*out) += ret; break; case 's': - const char* str = va_arg(ap, const char*); + const char* str = va_arg(*ap, const char*); if (ret > n) break; for (; *str; str ++, (*out) ++, ret ++ ) { if (ret >= n) { @@ -48,20 +47,19 @@ static inline int print_fmt(char **out, int n, const char** fmt, void* _ap) { } break; case 'c': - char ch = va_arg(ap, int); + char ch = va_arg(*ap, int); ret = 1; **out = ch; (*out) ++; break; case 'x': - ret = num_to_ascii(va_arg(ap, int), 16, n, *out); + ret = num_to_ascii(va_arg(*ap, int), 16, n, *out); (*out) += ret; break; default: break; } (*fmt) ++; - *(va_list*)_ap = ap; return ret; } @@ -71,7 +69,7 @@ int rvsnprintf(char* out, size_t n, const char* fmt, va_list ap) { if (*fmt == '%') { // FIXME fmt++; - print_fmt(&out, 123, &fmt, &ap); + print_fmt(&out, 123, &fmt, (va_list*)&ap); continue; } *out = *fmt; diff --git a/abstract-machine/klib/src/stdlib.c b/abstract-machine/klib/src/stdlib.c index e421ca7..13c4e25 100644 --- a/abstract-machine/klib/src/stdlib.c +++ b/abstract-machine/klib/src/stdlib.c @@ -40,7 +40,7 @@ void *malloc(size_t size) { ptr += size; return ptr - size; #endif - return NULL; + return ptr; } void free(void *ptr) {