]> git.ipfire.org Git - thirdparty/git.git/commitdiff
trace2: NULL is not allowed for va_list
authorTorsten Bögershausen <tboegi@web.de>
Tue, 19 Mar 2019 17:13:46 +0000 (17:13 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Mar 2019 00:48:53 +0000 (09:48 +0900)
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>
trace2.c
trace2.h
trace2/tr2_tgt_event.c
trace2/tr2_tgt_normal.c
trace2/tr2_tgt_perf.c

index ccccd4ef0919eebe1eff5834df3016778b0459d1..8bbad568871dc2a8526d47ae4cb9f36f49fcb7a3 100644 (file)
--- a/trace2.c
+++ b/trace2.c
@@ -548,10 +548,14 @@ void trace2_region_enter_printf_va_fl(const char *file, int line,
 }
 
 void trace2_region_enter_fl(const char *file, int line, const char *category,
-                           const char *label, const struct repository *repo)
+                           const char *label, const struct repository *repo, ...)
 {
+       va_list ap;
+       va_start(ap, repo);
        trace2_region_enter_printf_va_fl(file, line, category, label, repo,
-                                        NULL, NULL);
+                                        NULL, ap);
+       va_end(ap);
+
 }
 
 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,
 }
 
 void trace2_region_leave_fl(const char *file, int line, const char *category,
-                           const char *label, const struct repository *repo)
+                           const char *label, const struct repository *repo, ...)
 {
+       va_list ap;
+       va_start(ap, repo);
        trace2_region_leave_printf_va_fl(file, line, category, label, repo,
-                                        NULL, NULL);
+                                        NULL, ap);
+       va_end(ap);
 }
 
 void trace2_region_leave_printf_fl(const char *file, int line,
index ae5020d0e66e08d86e0eb1398bce884c29de4487..b330a54a89a08c2e1f764db6708a8f55a7479f3b 100644 (file)
--- a/trace2.h
+++ b/trace2.h
@@ -238,7 +238,7 @@ void trace2_def_repo_fl(const char *file, int line, struct repository *repo);
  * on this thread.
  */
 void trace2_region_enter_fl(const char *file, int line, const char *category,
-                           const char *label, const struct repository *repo);
+                           const char *label, const struct repository *repo, ...);
 
 #define trace2_region_enter(category, label, repo) \
        trace2_region_enter_fl(__FILE__, __LINE__, (category), (label), (repo))
@@ -278,7 +278,7 @@ void trace2_region_enter_printf(const char *category, const char *label,
  * in this nesting level.
  */
 void trace2_region_leave_fl(const char *file, int line, const char *category,
-                           const char *label, const struct repository *repo);
+                           const char *label, const struct repository *repo, ...);
 
 #define trace2_region_leave(category, label, repo) \
        trace2_region_leave_fl(__FILE__, __LINE__, (category), (label), (repo))
index 107cb5317d2270ccf8b54727fb55f4526a503c24..1cf4f62441c9307d610ebb0274ddb272ec2b8f01 100644 (file)
@@ -190,7 +190,7 @@ static void fn_atexit(uint64_t us_elapsed_absolute, int code)
 static void maybe_add_string_va(struct json_writer *jw, const char *field_name,
                                const char *fmt, va_list ap)
 {
-       if (fmt && *fmt && ap) {
+       if (fmt && *fmt) {
                va_list copy_ap;
                struct strbuf buf = STRBUF_INIT;
 
index 547183d5b64169acfc1e8f9b1f62501de36240ef..1a07d70abd6de281fc2a865f026fbb2e426adf96 100644 (file)
@@ -126,7 +126,7 @@ static void fn_atexit(uint64_t us_elapsed_absolute, int code)
 static void maybe_append_string_va(struct strbuf *buf, const char *fmt,
                                   va_list ap)
 {
-       if (fmt && *fmt && ap) {
+       if (fmt && *fmt) {
                va_list copy_ap;
 
                va_copy(copy_ap, ap);
index f0746fcf868ccab0408333bb954e7d531843af7d..2a866d701b201d36521cbd7d860d23f378a0f5b7 100644 (file)
@@ -211,7 +211,7 @@ static void fn_atexit(uint64_t us_elapsed_absolute, int code)
 static void maybe_append_string_va(struct strbuf *buf, const char *fmt,
                                   va_list ap)
 {
-       if (fmt && *fmt && ap) {
+       if (fmt && *fmt) {
                va_list copy_ap;
 
                va_copy(copy_ap, ap);