]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
netem: fix clang warnings
authorStephen Hemminger <stephen@networkplumber.org>
Tue, 11 Jan 2022 17:54:30 +0000 (09:54 -0800)
committerDavid Ahern <dsahern@kernel.org>
Wed, 26 Jan 2022 17:19:08 +0000 (10:19 -0700)
Netem is using empty format string to not print values.
Clang complains about this hack so don't do it.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
tc/q_netem.c

index f45a64b9d554fbaaf011a4f1797e85ed950415f1..26402e9ad93fe1bfe530c43027bf63006c4c16f6 100644 (file)
@@ -50,10 +50,12 @@ static void explain1(const char *arg)
 #define MAX_DIST       (16*1024)
 
 /* Print values only if they are non-zero */
-static void __print_int_opt(const char *label_json, const char *label_fp,
-                           int val)
+static void __attribute__((format(printf, 2, 0)))
+__print_int_opt(const char *label_json, const char *label_fp, int val)
 {
-       print_int(PRINT_ANY, label_json, val ? label_fp : "", val);
+       print_int(PRINT_JSON, label_json, NULL, val);
+       if (val != 0)
+               print_int(PRINT_FP, NULL, label_fp, val);
 }
 #define PRINT_INT_OPT(label, val)                      \
        __print_int_opt(label, " " label " %d", (val))
@@ -61,8 +63,8 @@ static void __print_int_opt(const char *label_json, const char *label_fp,
 /* Time print prints normally with varying units, but for JSON prints
  * in seconds (1ms vs 0.001).
  */
-static void __print_time64(const char *label_json, const char *label_fp,
-                          __u64 val)
+static void __attribute__((format(printf, 2, 0)))
+__print_time64(const char *label_json, const char *label_fp, __u64 val)
 {
        SPRINT_BUF(b1);
 
@@ -76,8 +78,8 @@ static void __print_time64(const char *label_json, const char *label_fp,
 /* Percent print prints normally in percentage points, but for JSON prints
  * an absolute value (1% vs 0.01).
  */
-static void __print_percent(const char *label_json, const char *label_fp,
-                           __u32 per)
+static void __attribute__((format(printf, 2, 0)))
+__print_percent(const char *label_json, const char *label_fp, __u32 per)
 {
        print_float(PRINT_FP, NULL, label_fp, (100. * per) / UINT32_MAX);
        print_float(PRINT_JSON, label_json, NULL, (1. * per) / UINT32_MAX);
@@ -795,9 +797,10 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
                rate64 = rate64 ? : rate->rate;
                tc_print_rate(PRINT_ANY, "rate", " rate %s", rate64);
                PRINT_INT_OPT("packetoverhead", rate->packet_overhead);
-               print_uint(PRINT_ANY, "cellsize",
-                          rate->cell_size ? " cellsize %u" : "",
-                          rate->cell_size);
+
+               print_uint(PRINT_JSON, "cellsize", NULL, rate->cell_size);
+               if (rate->cell_size)
+                       print_uint(PRINT_FP, NULL, " cellsize %u", rate->cell_size);
                PRINT_INT_OPT("celloverhead", rate->cell_overhead);
                close_json_object();
        }
@@ -817,9 +820,13 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
                close_json_object();
        }
 
-       print_bool(PRINT_ANY, "ecn", ecn ? " ecn " : "", ecn);
-       print_luint(PRINT_ANY, "gap", qopt.gap ? " gap %lu" : "",
-                   (unsigned long)qopt.gap);
+       print_bool(PRINT_JSON, "ecn", NULL, ecn);
+       if (ecn)
+               print_bool(PRINT_FP, NULL, " ecn ", ecn);
+
+       print_luint(PRINT_JSON, "gap", NULL, qopt.gap);
+       if (qopt.gap)
+               print_luint(PRINT_FP, NULL, " gap %lu", qopt.gap);
 
        return 0;
 }