Also added a test yielding a failure with the previous definition, i.e. when using: (va_end(ap)); The test also checks potentially incorrect va_start() definition.
Unified · Split
| @@ -25,7 +25,7 @@ void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); · 24 unmodified lines | ||
| 25 | 25 | #define va_arg(ap, type) \ |
| 26 | 26 | (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) |
| 27 | 27 | #define va_copy(dest, src) (*(dest) = *(src)) |
| 28 | −#define va_end(ap) | |
| 28 | +#define va_end(ap) ((void)0) | |
| 29 | 29 | |
| 30 | 30 | /* avoid conflicting definition for va_list on Macs. */ |
| 31 | 31 | #define _VA_LIST_T |
| @@ -36,7 +36,7 @@ typedef char *va_list; · 4 unmodified lines | ||
| 36 | 36 | #define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \ |
| 37 | 37 | ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8)) |
| 38 | 38 | #define va_copy(dest, src) ((dest) = (src)) |
| 39 | −#define va_end(ap) | |
| 39 | +#define va_end(ap) ((void)0) | |
| 40 | 40 | #endif |
| 41 | 41 | |
| 42 | 42 | #elif __arm__ |
| @@ -48,7 +48,7 @@ typedef char *va_list; · 5 unmodified lines | ||
| 48 | 48 | #define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ |
| 49 | 49 | &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) |
| 50 | 50 | #define va_copy(dest, src) (dest) = (src) |
| 51 | −#define va_end(ap) | |
| 51 | +#define va_end(ap) ((void)0) | |
| 52 | 52 | |
| 53 | 53 | #elif defined(__aarch64__) |
| 54 | 54 | typedef struct { |
| @@ -60,7 +60,7 @@ typedef struct { · 5 unmodified lines | ||
| 60 | 60 | } va_list; |
| 61 | 61 | #define va_start(ap, last) __va_start(ap, last) |
| 62 | 62 | #define va_arg(ap, type) __va_arg(ap, type) |
| 63 | −#define va_end(ap) | |
| 63 | +#define va_end(ap) ((void)0) | |
| 64 | 64 | #define va_copy(dest, src) ((dest) = (src)) |
| 65 | 65 | |
| 66 | 66 | #else /* __i386__ */ |
| @@ -69,7 +69,7 @@ typedef char *va_list; · 2 unmodified lines | ||
| 69 | 69 | #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) |
| 70 | 70 | #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) |
| 71 | 71 | #define va_copy(dest, src) (dest) = (src) |
| 72 | −#define va_end(ap) | |
| 72 | +#define va_end(ap) ((void)0) | |
| 73 | 73 | #endif |
| 74 | 74 | |
| 75 | 75 | /* fix a buggy dependency on GCC in libio.h */ |
| @@ -2622,6 +2622,19 @@ void stdarg_for_libc(const char *fmt, ...) · 2621 unmodified lines | ||
| 2622 | 2622 | va_end(args); |
| 2623 | 2623 | } |
| 2624 | 2624 | |
| 2625 | +void stdarg_syntax(int n, ...) | |
| 2626 | +{ | |
| 2627 | + int i; | |
| 2628 | + va_list ap; | |
| 2629 | + if (1) | |
| 2630 | + va_start(ap, n); | |
| 2631 | + else | |
| 2632 | + ; | |
| 2633 | + i = va_arg(ap, int); | |
| 2634 | + printf("stdarg_void_expr: %d\n", i); | |
| 2635 | + (va_end(ap)); | |
| 2636 | +} | |
| 2637 | + | |
| 2625 | 2638 | void stdarg_test(void) |
| 2626 | 2639 | { |
| 2627 | 2640 | LONG_DOUBLE ld = 1234567891234LL; |
| @@ -2669,6 +2682,7 @@ void stdarg_test(void) · 41 unmodified lines | ||
| 2669 | 2682 | bob.profile = 42; |
| 2670 | 2683 | stdarg_for_struct(bob, bob, bob, bob.profile); |
| 2671 | 2684 | stdarg_for_libc("stdarg_for_libc: %s %.2f %d\n", "string", 1.23, 456); |
| 2685 | + stdarg_syntax(1, 17); | |
| 2672 | 2686 | } |
| 2673 | 2687 | |
| 2674 | 2688 | void whitespace_test(void) |