Skip to contentSkip to conversation

tools-accounting-getdelays-fix-wformat-truncation-warning-in-format_timespec.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message May 29

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: tools/accounting/getdelays: fix -Wformat-truncation warning in format_timespec
has been removed from the -mm tree. Its filename was
tools-accounting-getdelays-fix-wformat-truncation-warning-in-format_timespec.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Yiyang Chen <[email protected]>
Subject: tools/accounting/getdelays: fix -Wformat-truncation warning in format_timespec
Date: Thu, 23 Apr 2026 23:11:39 +0800

Reproduce with GCC 13.3.0:

  $ cd tools/accounting
  $ make

This emits:

getdelays.c: In function `format_timespec':
getdelays.c:218:67: warning: `:' directive output may be truncated writing 1 byte into a region of size between 0 and 16 [-Wformat-truncation=]
218 | snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d",

      |

getdelays.c:218:9: note: `snprintf' output between 20 and 72 bytes into a destination of size 32

The problem is that %04d and %02d specify minimum field widths only. GCC cannot prove that formatting tm_year + 1900 and the other struct tm fields will always fit in the fixed 32-byte buffer, so it warns about possible truncation.

Fix this by replacing the manual snprintf() formatting with strftime("%Y-%m-%dT%H:%M:%S", ...). That matches the data we already have in struct tm, keeps the intended timestamp format, and avoids the warning when building tools/accounting with GCC.

---

 tools/accounting/getdelays.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
tools/accounting/getdelays.c renamed from tools/accounting/getdelays.c~tools-accounting-getdelays-fix-wformat-truncation-warning-in-format_timespec +1 -7
@@ -241,13 +241,7 @@ static const char *format_timespec(struc
 	if (localtime_r(&time_sec, &tm_info) == NULL)
 		return "N/A";
 
-	snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d",
-		tm_info.tm_year + 1900,
-		tm_info.tm_mon + 1,
-		tm_info.tm_mday,
-		tm_info.tm_hour,
-		tm_info.tm_min,
-		tm_info.tm_sec);
+	strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S", &tm_info);
 
 	return buffer;
 }

_

Patches currently in -mm which might be from [email protected] are