trace2: NULL is not allowed for va_list

Some compilers don't allow NULL to be passed for a va_list, and e.g. "gcc (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516" errors out like this: trace2/tr2_tgt_event.c:193:18: error: invalid operands to binary && (have ‘int’ and ‘va_list {aka __va_list}’) if (fmt && *fmt && ap) { ^^ I couldn't find any hints that va_list and pointers can be mixed, and no hints that they can't either. Morten Welinder comments: "C99, Section 7.15, simply says that va_list "is an object type suitable for holding information needed by the macros va_start, va_end, and va_copy". So clearly not guaranteed to be mixable with pointers... The portable solution is to use "va_list" everywhere in the callchain. As a consequence, both trace2_region_enter_fl() and trace2_region_leave_fl() now take a variable argument list. Signed-off-by: Torsten Bögershausen <tboegi@web.de> Acked-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Mar 19, 2019 at 17:13 UTC ad006fe419efda47b0012347c5c2925f9a082101
5 files changed +16 -9
trace2.c
+11 -4
@@ -548,10 +548,14 @@ void trace2_region_enter_printf_va_fl(const char *file, int line,
548 }
549
550 void trace2_region_enter_fl(const char *file, int line, const char *category,
551 - const char *label, const struct repository *repo)
551 + const char *label, const struct repository *repo, ...)
552 {
553 + va_list ap;
554 + va_start(ap, repo);
555 trace2_region_enter_printf_va_fl(file, line, category, label, repo,
554 - NULL, NULL);
556 + NULL, ap);
557 + va_end(ap);
558 +
559 }
560
561 void trace2_region_enter_printf_fl(const char *file, int line,
@@ -621,10 +625,13 @@ void trace2_region_leave_printf_va_fl(const char *file, int line,
625 }
626
627 void trace2_region_leave_fl(const char *file, int line, const char *category,
624 - const char *label, const struct repository *repo)
628 + const char *label, const struct repository *repo, ...)
629 {
630 + va_list ap;
631 + va_start(ap, repo);
632 trace2_region_leave_printf_va_fl(file, line, category, label, repo,
627 - NULL, NULL);
633 + NULL, ap);
634 + va_end(ap);
635 }
636
637 void trace2_region_leave_printf_fl(const char *file, int line,
trace2.h
+2 -2
@@ -238,7 +238,7 @@ void trace2_def_repo_fl(const char *file, int line, struct repository *repo);
238 * on this thread.
239 */
240 void trace2_region_enter_fl(const char *file, int line, const char *category,
241 - const char *label, const struct repository *repo);
241 + const char *label, const struct repository *repo, ...);
242
243 #define trace2_region_enter(category, label, repo) \
244 trace2_region_enter_fl(__FILE__, __LINE__, (category), (label), (repo))
@@ -278,7 +278,7 @@ void trace2_region_enter_printf(const char *category, const char *label,
278 * in this nesting level.
279 */
280 void trace2_region_leave_fl(const char *file, int line, const char *category,
281 - const char *label, const struct repository *repo);
281 + const char *label, const struct repository *repo, ...);
282
283 #define trace2_region_leave(category, label, repo) \
284 trace2_region_leave_fl(__FILE__, __LINE__, (category), (label), (repo))
trace2/tr2_tgt_event.c
+1 -1
@@ -190,7 +190,7 @@ static void fn_atexit(uint64_t us_elapsed_absolute, int code)
190 static void maybe_add_string_va(struct json_writer *jw, const char *field_name,
191 const char *fmt, va_list ap)
192 {
193 - if (fmt && *fmt && ap) {
193 + if (fmt && *fmt) {
194 va_list copy_ap;
195 struct strbuf buf = STRBUF_INIT;
196
trace2/tr2_tgt_normal.c
+1 -1
@@ -126,7 +126,7 @@ static void fn_atexit(uint64_t us_elapsed_absolute, int code)
126 static void maybe_append_string_va(struct strbuf *buf, const char *fmt,
127 va_list ap)
128 {
129 - if (fmt && *fmt && ap) {
129 + if (fmt && *fmt) {
130 va_list copy_ap;
131
132 va_copy(copy_ap, ap);
trace2/tr2_tgt_perf.c
+1 -1
@@ -211,7 +211,7 @@ static void fn_atexit(uint64_t us_elapsed_absolute, int code)
211 static void maybe_append_string_va(struct strbuf *buf, const char *fmt,
212 va_list ap)
213 {
214 - if (fmt && *fmt && ap) {
214 + if (fmt && *fmt) {
215 va_list copy_ap;
216
217 va_copy(copy_ap, ap);