]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
iproute: make clang happy
authorMahesh Bandewar <maheshb@google.com>
Thu, 23 Aug 2018 01:01:37 +0000 (18:01 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 30 Aug 2018 14:58:09 +0000 (07:58 -0700)
These are primarily fixes for "string is not string literal" warnings
/ errors (with -Werror -Wformat-nonliteral). This should be a no-op
change. I had to replace couple of print helper functions with the
code they call as it was becoming harder to eliminate these warnings,
however these helpers were used only at couple of places, so no
major change as such.

Signed-off-by: Mahesh Bandewar <maheshb@google.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
include/json_writer.h
ip/iplink_can.c
lib/color.c
lib/json_print.c
lib/json_writer.c
misc/ss.c
tc/m_ematch.c
tc/m_ematch.h

index 9ab88e1dbdd9136f1189c4849248dbf23548a129..0c8831c1136df2bcefca9febcc31ceeb5b672c89 100644 (file)
@@ -29,6 +29,7 @@ void jsonw_pretty(json_writer_t *self, bool on);
 void jsonw_name(json_writer_t *self, const char *name);
 
 /* Add value  */
+__attribute__((format(printf, 2, 3)))
 void jsonw_printf(json_writer_t *self, const char *fmt, ...);
 void jsonw_string(json_writer_t *self, const char *value);
 void jsonw_bool(json_writer_t *self, bool value);
@@ -59,8 +60,6 @@ void jsonw_luint_field(json_writer_t *self, const char *prop,
                        unsigned long int num);
 void jsonw_lluint_field(json_writer_t *self, const char *prop,
                        unsigned long long int num);
-void jsonw_float_field_fmt(json_writer_t *self, const char *prop,
-                          const char *fmt, double val);
 
 /* Collections */
 void jsonw_start_object(json_writer_t *self);
index 587413da15c476fb6abbd9d47df9ec52986bb7d6..c0deeb1f1fcf38e466ce38d8c1ebebab399db669 100644 (file)
@@ -316,11 +316,14 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]);
 
                if (is_json_context()) {
+                       json_writer_t *jw;
+
                        open_json_object("bittiming");
                        print_int(PRINT_ANY, "bitrate", NULL, bt->bitrate);
-                       jsonw_float_field_fmt(get_json_writer(),
-                                             "sample_point", "%.3f",
-                                             (float) bt->sample_point / 1000.);
+                       jw = get_json_writer();
+                       jsonw_name(jw, "sample_point");
+                       jsonw_printf(jw, "%.3f",
+                                    (float) bt->sample_point / 1000);
                        print_int(PRINT_ANY, "tq", NULL, bt->tq);
                        print_int(PRINT_ANY, "prop_seg", NULL, bt->prop_seg);
                        print_int(PRINT_ANY, "phase_seg1",
@@ -415,12 +418,14 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                        RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
 
                if (is_json_context()) {
+                       json_writer_t *jw;
+
                        open_json_object("data_bittiming");
                        print_int(PRINT_JSON, "bitrate", NULL, dbt->bitrate);
-                       jsonw_float_field_fmt(get_json_writer(),
-                                             "sample_point",
-                                             "%.3f",
-                                             (float) dbt->sample_point / 1000.);
+                       jw = get_json_writer();
+                       jsonw_name(jw, "sample_point");
+                       jsonw_printf(jw, "%.3f",
+                                    (float) dbt->sample_point / 1000.);
                        print_int(PRINT_JSON, "tq", NULL, dbt->tq);
                        print_int(PRINT_JSON, "prop_seg", NULL, dbt->prop_seg);
                        print_int(PRINT_JSON, "phase_seg1",
index eaf69e74d673a6e949e68c504d54777927789b79..e5406294dfc4bafe5b7a4083c25e17e7cbd21b3c 100644 (file)
@@ -132,6 +132,7 @@ void set_color_palette(void)
                is_dark_bg = 1;
 }
 
+__attribute__((format(printf, 3, 4)))
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 {
        int ret = 0;
index 5dc41bfabfd4db84965c43d83dfd80ee09c37939..77902824a7386bf617bace5be8bec9cfd379f6da 100644 (file)
@@ -100,6 +100,7 @@ void close_json_array(enum output_type type, const char *str)
  * functions handling different types
  */
 #define _PRINT_FUNC(type_name, type)                                   \
+       __attribute__((format(printf, 4, 0)))                           \
        void print_color_##type_name(enum output_type t,                \
                                     enum color_attr color,             \
                                     const char *key,                   \
index aa9ce1c65e513567f1160248772b7ea4a9caa18b..68890b34ee92f583ee9eb8497bcb7156adf14748 100644 (file)
@@ -152,6 +152,7 @@ void jsonw_name(json_writer_t *self, const char *name)
                putc(' ', self->out);
 }
 
+__attribute__((format(printf, 2, 3)))
 void jsonw_printf(json_writer_t *self, const char *fmt, ...)
 {
        va_list ap;
@@ -205,11 +206,6 @@ void jsonw_null(json_writer_t *self)
        jsonw_printf(self, "null");
 }
 
-void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num)
-{
-       jsonw_printf(self, fmt, num);
-}
-
 void jsonw_float(json_writer_t *self, double num)
 {
        jsonw_printf(self, "%g", num);
@@ -274,15 +270,6 @@ void jsonw_float_field(json_writer_t *self, const char *prop, double val)
        jsonw_float(self, val);
 }
 
-void jsonw_float_field_fmt(json_writer_t *self,
-                          const char *prop,
-                          const char *fmt,
-                          double val)
-{
-       jsonw_name(self, prop);
-       jsonw_float_fmt(self, fmt, val);
-}
-
 void jsonw_uint_field(json_writer_t *self, const char *prop, unsigned int num)
 {
        jsonw_name(self, prop);
index b2c634c8dd7eb7560f5259dcdd88324ecd1faf5e..f99b6874c2281d7160d1e7227e0df2406fc5dddd 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -977,6 +977,7 @@ static int buf_update(int len)
 }
 
 /* Append content to buffer as part of the current field */
+__attribute__((format(printf, 1, 2)))
 static void out(const char *fmt, ...)
 {
        struct column *f = current_field;
@@ -1094,7 +1095,7 @@ static void print_header(void)
 {
        while (!field_is_last(current_field)) {
                if (!current_field->disabled)
-                       out(current_field->header);
+                       out("%s", current_field->header);
                field_next();
        }
 }
index ace4b3dd738ba5aa4e1273b354e1822ad225f607..a524b520b27625857aa300a8b3c24a5e6951a0ea 100644 (file)
@@ -277,6 +277,7 @@ static int flatten_tree(struct ematch *head, struct ematch *tree)
        return count;
 }
 
+__attribute__((format(printf, 5, 6)))
 int em_parse_error(int err, struct bstr *args, struct bstr *carg,
                   struct ematch_util *e, char *fmt, ...)
 {
index ff02d7ac91123602fe24fe3f521e1e7593729f3c..356f2eded7fc9e2c0c93ab4479b128fdf0afac8b 100644 (file)
@@ -102,6 +102,7 @@ static inline int parse_layer(const struct bstr *b)
                return INT_MAX;
 }
 
+__attribute__((format(printf, 5, 6)))
 int em_parse_error(int err, struct bstr *args, struct bstr *carg,
                   struct ematch_util *, char *fmt, ...);
 int print_ematch(FILE *, const struct rtattr *);