From f003ccf16b141836758183a3f9f984f970289a7a Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Sat, 13 Apr 2024 22:41:43 +0300 Subject: [PATCH] ospfd: Fix compile warning with `-Wformat-truncation` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ospfd/ospf_sr.c: In function ‘show_sr_node.part.5’: ospfd/ospf_sr.c:2745:32: warning: ‘%u’ directive output may be truncated writing between 1 and 10 bytes into a region of size 2 [-Wformat-truncation=] snprintf(tmp, sizeof(tmp), "%u", i); ^~ ospfd/ospf_sr.c:2745:31: note: directive argument in the range [0, 2147483646] snprintf(tmp, sizeof(tmp), "%u", i); Signed-off-by: Donatas Abraitis --- ospfd/ospf_sr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c index e26fe6f53a..198309c1ef 100644 --- a/ospfd/ospf_sr.c +++ b/ospfd/ospf_sr.c @@ -2740,9 +2740,9 @@ static void show_sr_node(struct vty *vty, struct json_object *json, if (srn->algo[i] == SR_ALGORITHM_UNSET) continue; json_obj = json_object_new_object(); - char tmp[2]; + char tmp[12]; - snprintf(tmp, sizeof(tmp), "%u", i); + snprintf(tmp, sizeof(tmp), "%d", i); json_object_string_add(json_obj, tmp, srn->algo[i] == SR_ALGORITHM_SPF ? "SPF" -- 2.39.5