From nobody Wed Jun 17 07:21:02 2026 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E16CB29A9C3 for ; Thu, 23 Apr 2026 15:11:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776957113; cv=none; b=k++nZfD/3Wo0AX94OUZ56brW7zCbrpChnC1S9SABh1YYxaGIlWtXsJQ98Xiohl3OfaakmMD9zbxzG4jKQFul613ISjM353/TEZYHvSQHBpwIVedUFH2jNiPFwYyvVAp5ZIXaNXRS61TXY5fTLEc42q2/2d7IfX+hK0mb3usvB9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776957113; c=relaxed/simple; bh=QktIHByUUfXuI8wdb5IU9k7poh9gqebH5XRqXgw35KU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=GM6ZN5nels/7ME6e81cfTU02Sv7hzp9vr010b7Ps4FI08m09RxgGoUyvLICDb2KrbN/nTGppk7tYh/McU8ZqkBK2XL842EyhiY93JrpJ2KE6YGODtNl3fNVGbJsIjaYMK/IVypdh2rgV/d6aadJbiXf1TTfJaXQAT/ZSTluk8lY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RWmXKejO; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RWmXKejO" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-3591cc98871so3122951a91.3 for ; Thu, 23 Apr 2026 08:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776957111; x=1777561911; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8dcQ7rvWnVBiPEhvNZ0fkqp05hmhgDGfFFdOaD0CvKM=; b=RWmXKejO3sSk14fULm8ekIjtU7Rz0nocOnAh4wmPhVISoPqTtsC7fo5RlO+5/97LxU z0C3y2ruJ0lp3xGqgWgJgI7cRgCGeCtOayLzSTaYiiDJfjgYZK3F+YSazCMqs3Bflf72 AqpOwnrq9n9PK6wQCey64/GHG2PYOFo2tTgdE5IaOD1N/jbh4CMfU1holmMz6UFBoTPM mrxvIN3VMbg68tPlV2BzUqhmVaZLM/goLDplpCjfzmcJlqW30sC30SkfyvUBKaOPTHKK BpAKl6yJyDwacVVgEzhKUmsMPcsAH+V+xqK+7LwEW6MulfGS907g0MjOW9wOyvy0IoiH LzsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776957111; x=1777561911; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8dcQ7rvWnVBiPEhvNZ0fkqp05hmhgDGfFFdOaD0CvKM=; b=HBUnsciifK94t6ECL2SlFF0LDiHTbYtA4ecSw92l3sqLCZrFt8hc+vUl9IT6vTAepC eCIPSRCAdh4vZ26UFP1On2Zo44SuLWgXfJPfrUJvHQB/dG75MAgGwl/DXcfBIcDhDJVX f8vXJ2jhW46BkAw84f71vuMl1MVmn05039W60s+z0E1FePihXGQaeQAqOpKzExh0EVPN uN93se2siYzdTYw8v+hDRE3TD8M5m44jsunbWCKSZAEZcGTq6fDLyyEDABdF3c5RvOvl /ykL1IgzbO3zfzSkgxAt+p50Zwf8mzUL3Vdb3nr2WN0TgNP2ueK5yydeQu5t/maft99k bp4Q== X-Gm-Message-State: AOJu0Yz4YGcBVSwLq4NlP5QOzCFtl0zFBMvYmIDrcbKB7bDMOF9SkH93 eQOVCIhMeXGDdJul/7ztDG15HwVqF/FkFOqsPptMNpwf1W1n99r9GuA1glFgPo2m X-Gm-Gg: AeBDieuvgbn+3lNL+KAcXnNW/tV1Ay9V7jSqTTLbO6Fnd8rtSNI7Ih7N+pVCj9/OSiu lhzQfzhnfFZl9zVVJhhsLqxuRe0ysWWK83NeLmWQy9Eyw96X97AIR2qwOPj92mloUy3BneFgDiW JmRRHAVZd2x0BG+YWmFplhe0Y5ACVQZPpGS8RsTnOolktK8ubsX5ajVOBaO6Shmm0/nwPsTTNBM /pjTgnhwtc8DG6HhhxUCGXsNjy6nTUmdPnbVva021OggUibNjYhq1fsZOzNRlz+aH+L6qvZ2xOa XjwDbDGwqdrMO+njeTSdvc1HFmLq6AXsXZtM9INZX4JJcj7a0TEo2oYMSO8T25MwjqPEhqh2NWt 1dlGQB9fC1g0Q6lg4UoH6B0TdzUwn1Q+EweAnxkgwQHfh6eesnAyZxPRVvUqjSsiNqnlj6y2Lh7 jLcoX44PQXukQNmaxgxVeSlSsIgqz053e5cbXe8zDGybw= X-Received: by 2002:a17:902:d501:b0:2b2:5099:2f3e with SMTP id d9443c01a7336-2b5f9e7be29mr307112695ad.4.1776957111050; Thu, 23 Apr 2026 08:11:51 -0700 (PDT) Received: from ubuntu24.lan ([14.21.197.90]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab32cfasm253942645ad.69.2026.04.23.08.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 08:11:50 -0700 (PDT) From: Yiyang Chen To: akpm@linux-foundation.org, wang.yaxin@zte.com.cn, fan.yu9@zte.com.cn Cc: linux-kernel@vger.kernel.org, Yiyang Chen Subject: [PATCH] tools/accounting/getdelays: fix -Wformat-truncation warning in format_timespec Date: Thu, 23 Apr 2026 23:11:39 +0800 Message-ID: <87d9723e0b59d816ee2e4bd7cddd58a54c6c9f91.1776956545.git.cyyzero16@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Reproduce with GCC 13.3.0: $ cd tools/accounting $ make This emits: getdelays.c: In function =E2=80=98format_timespec=E2=80=99: getdelays.c:218:67: warning: =E2=80=98:=E2=80=99 directive output may be tr= uncated writing 1 byte into a region of size between 0 and 16 [-Wformat-tru= ncation=3D] 218 | snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:= %02d", | getdelays.c:218:9: note: =E2=80=98snprintf=E2=80=99 output between 20 and 7= 2 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. Signed-off-by: Yiyang Chen --- tools/accounting/getdelays.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tools/accounting/getdelays.c b/tools/accounting/getdelays.c index 368a622ca027..caa5fe9dd573 100644 --- a/tools/accounting/getdelays.c +++ b/tools/accounting/getdelays.c @@ -241,13 +241,7 @@ static const char *format_timespec(struct __kernel_tim= espec *ts) if (localtime_r(&time_sec, &tm_info) =3D=3D NULL) return "N/A"; =20 - 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); =20 return buffer; } --=20 2.43.0