]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: clean up zebra_protodown_rc_str()
authorMark Stapp <mjs@voltanet.io>
Thu, 29 Oct 2020 16:03:25 +0000 (12:03 -0400)
committerMark Stapp <mjs@voltanet.io>
Thu, 29 Oct 2020 16:03:25 +0000 (12:03 -0400)
Clean up api SA warning, use 'const', and replace snprintf+
pointer math with strlcat.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
zebra/interface.c
zebra/interface.h

index 67be781938346e178e3ba2381b68f3026185383a..ddad9c9e56e3d89da8c21a6dba01daba211b2706 100644 (file)
@@ -1400,36 +1400,30 @@ static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf)
        vty_out(vty, "\n");
 }
 
-char *zebra_protodown_rc_str(enum protodown_reasons protodown_rc, char *pd_buf,
-                            uint32_t pd_buf_len)
+const char *zebra_protodown_rc_str(enum protodown_reasons protodown_rc,
+                                  char *pd_buf, uint32_t pd_buf_len)
 {
        bool first = true;
 
        pd_buf[0] = '\0';
 
-       snprintf(pd_buf + strlen(pd_buf), pd_buf_len - strlen(pd_buf), "(");
+       strlcat(pd_buf, "(", pd_buf_len);
 
        if (protodown_rc & ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY) {
                if (first)
                        first = false;
                else
-                       snprintf(pd_buf + strlen(pd_buf),
-                                pd_buf_len - strlen(pd_buf), ",");
-               snprintf(pd_buf + strlen(pd_buf), pd_buf_len - strlen(pd_buf),
-                        "startup-delay");
+                       strlcat(pd_buf, ",", pd_buf_len);
+               strlcat(pd_buf, "startup-delay", pd_buf_len);
        }
 
        if (protodown_rc & ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN) {
-               if (first)
-                       first = false;
-               else
-                       snprintf(pd_buf + strlen(pd_buf),
-                                pd_buf_len - strlen(pd_buf), ",");
-               snprintf(pd_buf + strlen(pd_buf), pd_buf_len - strlen(pd_buf),
-                        "uplinks-down");
+               if (!first)
+                       strlcat(pd_buf, ",", pd_buf_len);
+               strlcat(pd_buf, "uplinks-down", pd_buf_len);
        }
 
-       snprintf(pd_buf + strlen(pd_buf), pd_buf_len - strlen(pd_buf), ")");
+       strlcat(pd_buf, ")", pd_buf_len);
 
        return pd_buf;
 }
index a925dcc9628820a34757b60572bb7df328f68111..ab1a245e5e164a0c31b0f1e5269c47682e441968 100644 (file)
@@ -491,8 +491,8 @@ extern bool if_nhg_dependents_is_empty(const struct interface *ifp);
 extern void vrf_add_update(struct vrf *vrfp);
 extern void zebra_l2_map_slave_to_bond(struct zebra_if *zif, vrf_id_t vrf);
 extern void zebra_l2_unmap_slave_from_bond(struct zebra_if *zif);
-extern char *zebra_protodown_rc_str(enum protodown_reasons protodown_rc,
-                                   char *pd_buf, uint32_t pd_buf_len);
+extern const char *zebra_protodown_rc_str(enum protodown_reasons protodown_rc,
+                                         char *pd_buf, uint32_t pd_buf_len);
 
 #ifdef HAVE_PROC_NET_DEV
 extern void ifstat_update_proc(void);