# HG changeset patch # User Josef 'Jeff' Sipek # Date 1736725821 18000 # Sun Jan 12 18:50:21 2025 -0500 # Node ID 4cd363673b6c1f2bf775b77686fe2b1a415c8ee3 # Parent 47664546fbcab80169ccf1781d58cfb1f6399af4 contest: fix network ui age string truncation warning gcc 11-14 warn: ui-net.c:114:76: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=] The longest string we ever want to write to age_buf is 6 chars ("XXmYYs") and a nul. It is possible that the string strinks in length (eg., from "10s" to "0s") so we need to overwrite whatever was on the screen. The easiest way is to construct the string and then specify the string width and alignment when actually displaying it using mvwprintw. Signed-off-by: Josef 'Jeff' Sipek diff --git a/hlog/contest/ui-net.c b/hlog/contest/ui-net.c --- a/hlog/contest/ui-net.c +++ b/hlog/contest/ui-net.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Josef 'Jeff' Sipek + * Copyright (c) 2024-2025 Josef 'Jeff' Sipek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -111,18 +111,18 @@ if (secs >= (100 * 60)) { age = ">=100m"; } else if (secs > 59) { - snprintf(age_buf, sizeof(age_buf), "%um%us ", + snprintf(age_buf, sizeof(age_buf), "%um%us", secs / 60, secs % 60); age = age_buf; } else { - snprintf(age_buf, sizeof(age_buf), "%us ", + snprintf(age_buf, sizeof(age_buf), "%us", secs); age = age_buf; } } mvwprintw(lines_win, i, 0, "%s", lines[i]->buf); - mvwprintw(lines_win, i, lwidth - 5 - 1, "%s", age); + mvwprintw(lines_win, i, lwidth - 5 - 1, "%-6s", age); } MXUNLOCK(&lines_lock);