diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2020-04-20 20:12:38 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2020-04-21 01:14:33 +0200 |
commit | 772270f3b6a37a2dd9432541cce436e9b45bb6b9 (patch) | |
tree | fc7f717a60d056b0300fcf43373a1fff30b94b13 /ospfd/ospf_sr.c | |
parent | tools: add more macros to cocci.h (diff) | |
download | frr-772270f3b6a37a2dd9432541cce436e9b45bb6b9.tar.xz frr-772270f3b6a37a2dd9432541cce436e9b45bb6b9.zip |
*: sprintf -> snprintf
Replace sprintf with snprintf where straightforward to do so.
- sprintf's into local scope buffers of known size are replaced with the
equivalent snprintf call
- snprintf's into local scope buffers of known size that use the buffer
size expression now use sizeof(buffer)
- sprintf(buf + strlen(buf), ...) replaced with snprintf() into temp
buffer followed by strlcat
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'ospfd/ospf_sr.c')
-rw-r--r-- | ospfd/ospf_sr.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c index 7a786ba7a..2a35bd2ef 100644 --- a/ospfd/ospf_sr.c +++ b/ospfd/ospf_sr.c @@ -2094,7 +2094,7 @@ static void show_sr_node(struct vty *vty, struct json_object *json, json_obj = json_object_new_object(); char tmp[2]; - snprintf(tmp, 2, "%u", i); + snprintf(tmp, sizeof(tmp), "%u", i); json_object_string_add(json_obj, tmp, srn->algo[i] == SR_ALGORITHM_SPF ? "SPF" @@ -2129,13 +2129,15 @@ static void show_sr_node(struct vty *vty, struct json_object *json, "--------------------- --------- ---------------\n"); } for (ALL_LIST_ELEMENTS_RO(srn->ext_prefix, node, srp)) { - snprintf(pref, 19, "%s/%u", inet_ntoa(srp->nhlfe.prefv4.prefix), + snprintf(pref, sizeof(pref), "%s/%u", + inet_ntoa(srp->nhlfe.prefv4.prefix), srp->nhlfe.prefv4.prefixlen); - snprintf(sid, 22, "SR Pfx (idx %u)", srp->sid); + snprintf(sid, sizeof(sid), "SR Pfx (idx %u)", srp->sid); if (srp->nhlfe.label_out == MPLS_LABEL_IMPLICIT_NULL) - sprintf(label, "pop"); + snprintf(label, sizeof(label), "pop"); else - sprintf(label, "%u", srp->nhlfe.label_out); + snprintf(label, sizeof(label), "%u", + srp->nhlfe.label_out); itf = if_lookup_by_index(srp->nhlfe.ifindex, VRF_DEFAULT); if (json) { if (!json_prefix) { @@ -2164,14 +2166,15 @@ static void show_sr_node(struct vty *vty, struct json_object *json, } for (ALL_LIST_ELEMENTS_RO(srn->ext_link, node, srl)) { - snprintf(pref, 19, "%s/%u", + snprintf(pref, sizeof(pref), "%s/%u", inet_ntoa(srl->nhlfe[0].prefv4.prefix), srl->nhlfe[0].prefv4.prefixlen); - snprintf(sid, 22, "SR Adj. (lbl %u)", srl->sid[0]); + snprintf(sid, sizeof(sid), "SR Adj. (lbl %u)", srl->sid[0]); if (srl->nhlfe[0].label_out == MPLS_LABEL_IMPLICIT_NULL) - sprintf(label, "pop"); + snprintf(label, sizeof(label), "pop"); else - sprintf(label, "%u", srl->nhlfe[0].label_out); + snprintf(label, sizeof(label), "%u", + srl->nhlfe[0].label_out); itf = if_lookup_by_index(srl->nhlfe[0].ifindex, VRF_DEFAULT); if (json) { if (!json_link) { @@ -2194,11 +2197,13 @@ static void show_sr_node(struct vty *vty, struct json_object *json, json_object_array_add(json_link, json_obj); /* Backup Link */ json_obj = json_object_new_object(); - snprintf(sid, 22, "SR Adj. (lbl %u)", srl->sid[1]); + snprintf(sid, sizeof(sid), "SR Adj. (lbl %u)", + srl->sid[1]); if (srl->nhlfe[1].label_out == MPLS_LABEL_IMPLICIT_NULL) - sprintf(label, "pop"); + snprintf(label, sizeof(label), "pop"); else - sprintf(label, "%u", srl->nhlfe[0].label_out); + snprintf(label, sizeof(label), "%u", + srl->nhlfe[0].label_out); json_object_string_add(json_obj, "prefix", pref); json_object_int_add(json_obj, "sid", srl->sid[1]); json_object_int_add(json_obj, "inputLabel", @@ -2215,11 +2220,13 @@ static void show_sr_node(struct vty *vty, struct json_object *json, srl->nhlfe[0].label_in, label, sid, itf ? itf->name : "-", inet_ntoa(srl->nhlfe[0].nexthop)); - snprintf(sid, 22, "SR Adj. (lbl %u)", srl->sid[1]); + snprintf(sid, sizeof(sid), "SR Adj. (lbl %u)", + srl->sid[1]); if (srl->nhlfe[1].label_out == MPLS_LABEL_IMPLICIT_NULL) - sprintf(label, "pop"); + snprintf(label, sizeof(label), "pop"); else - sprintf(label, "%u", srl->nhlfe[1].label_out); + snprintf(label, sizeof(label), "%u", + srl->nhlfe[1].label_out); vty_out(vty, "%18s %8u %9s %21s %9s %15s\n", pref, srl->nhlfe[1].label_in, label, sid, itf ? itf->name : "-", |