History

Fix va_end() definition: must be an expression of type void

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.

Vincent Lefevre committed 7 years ago

Commit be7c8701 parent 920f7732 files · +19 −5Browse files

Unified · Split

2 files
  1. include/stdarg.h +5 −5
  2. tests/tcctest.c +14 −0
include/stdarg.h+5−5
@@ -25,7 +25,7 @@ void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); · 24 unmodified lines
2525 #define va_arg(ap, type) \
2626 (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))
2727 #define va_copy(dest, src) (*(dest) = *(src))
28−#define va_end(ap)
28+#define va_end(ap) ((void)0)
2929
3030 /* avoid conflicting definition for va_list on Macs. */
3131 #define _VA_LIST_T
@@ -36,7 +36,7 @@ typedef char *va_list; · 4 unmodified lines
3636 #define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
3737 ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
3838 #define va_copy(dest, src) ((dest) = (src))
39−#define va_end(ap)
39+#define va_end(ap) ((void)0)
4040 #endif
4141
4242 #elif __arm__
@@ -48,7 +48,7 @@ typedef char *va_list; · 5 unmodified lines
4848 #define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
4949 &~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
5050 #define va_copy(dest, src) (dest) = (src)
51−#define va_end(ap)
51+#define va_end(ap) ((void)0)
5252
5353 #elif defined(__aarch64__)
5454 typedef struct {
@@ -60,7 +60,7 @@ typedef struct { · 5 unmodified lines
6060 } va_list;
6161 #define va_start(ap, last) __va_start(ap, last)
6262 #define va_arg(ap, type) __va_arg(ap, type)
63−#define va_end(ap)
63+#define va_end(ap) ((void)0)
6464 #define va_copy(dest, src) ((dest) = (src))
6565
6666 #else /* __i386__ */
@@ -69,7 +69,7 @@ typedef char *va_list; · 2 unmodified lines
6969 #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
7070 #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
7171 #define va_copy(dest, src) (dest) = (src)
72−#define va_end(ap)
72+#define va_end(ap) ((void)0)
7373 #endif
7474
7575 /* fix a buggy dependency on GCC in libio.h */
tests/tcctest.c+14−0
@@ -2622,6 +2622,19 @@ void stdarg_for_libc(const char *fmt, ...) · 2621 unmodified lines
26222622 va_end(args);
26232623 }
26242624
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+
26252638 void stdarg_test(void)
26262639 {
26272640 LONG_DOUBLE ld = 1234567891234LL;
@@ -2669,6 +2682,7 @@ void stdarg_test(void) · 41 unmodified lines
26692682 bob.profile = 42;
26702683 stdarg_for_struct(bob, bob, bob, bob.profile);
26712684 stdarg_for_libc("stdarg_for_libc: %s %.2f %d\n", "string", 1.23, 456);
2685+ stdarg_syntax(1, 17);
26722686 }
26732687
26742688 void whitespace_test(void)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t