Skip to content

Commit 158baea

Browse files
DreamPearlscopeInfinity
authored andcommitted
Fix #32: va_arg for generic data types
1 parent e287bf1 commit 158baea

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/usr/include/stdarg.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ namespace std {
66
#endif
77

88
typedef struct va_list {
9-
int *base; // using int* to jmp at 4 bytes gap
9+
void *base;
1010
} va_list;
1111

12-
#define va_start(list, last) ((list).base = (((int*)&(last))+1))
12+
#define va_start(list, last) ((list).base = ((void*)(&(last)+1)))
1313
#define va_end(list) (list).base = NULL
14-
#define va_arg(list, type) (*(type*)((list).base++))
14+
#define va_arg(list, type) (*(type*)((list).base+=sizeof(type), \
15+
(list).base-sizeof(type)))
1516
#define va_copy(dst, src) (dst).base = (src).base
1617

1718
#ifdef __cplusplus

src/usr/lib/stdio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static int vsnprintf(char *s, size_t n, const char *fmt, va_list args) {
4242
s[len++]='%';
4343
break;
4444
case 'c':
45-
s[len++]=va_arg(args, char);
45+
s[len++]=(char)va_arg(args, int);
4646
break;
4747
case 's':
4848
innerstr = va_arg(args, const char*);

0 commit comments

Comments
 (0)