public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: robert.moore@intel.com, rafael.j.wysocki@intel.com, lenb@kernel.org
Cc: Shuah Khan <skhan@linuxfoundation.org>,
	linux-acpi@vger.kernel.org, devel@acpica.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn
Date: Wed, 16 Nov 2022 08:22:58 -0700	[thread overview]
Message-ID: <20221116152258.28772-1-skhan@linuxfoundation.org> (raw)

utprint module is included in tools/acpidump and when acpidump is built,
the following warning occurs.

 CC       tools/acpidump/utprint.o
/usr/include/x86_64-linux-gnu/bits/stdio2.h: In function ‘sprintf’:
../../../../../drivers/acpi/acpica/utprint.c:602:18: warning: specified bound 4294901760 exceeds ‘INT_MAX’ [-Wformat-truncation=]
  602 |         length = vsnprintf(string, ACPI_UINT32_MAX-ACPI_UINT16_MAX,
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  603 |                         format, args);
      |                         ~~~~~~~~~~~~~

Fix sprintf() to use ACPI_UINT32_MAX/2 to get rid of the truncate problem.
This change is inline other sprintf() implementations.

If using ACPI_UINT32_MAX is necessary in the kernel, acpidump might require
special case to get rid of this truncate problem.

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
 drivers/acpi/acpica/utprint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/acpica/utprint.c b/drivers/acpi/acpica/utprint.c
index d5aa2109847f..02cff16c8f77 100644
--- a/drivers/acpi/acpica/utprint.c
+++ b/drivers/acpi/acpica/utprint.c
@@ -599,7 +599,7 @@ int sprintf(char *string, const char *format, ...)
 	int length;
 
 	va_start(args, format);
-	length = vsnprintf(string, ACPI_UINT32_MAX, format, args);
+	length = vsnprintf(string, ACPI_UINT32_MAX/2, format, args);
 	va_end(args);
 
 	return (length);
-- 
2.34.1


             reply	other threads:[~2022-11-16 15:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 15:22 Shuah Khan [this message]
2022-11-16 19:05 ` [PATCH] ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn Rafael J. Wysocki
2022-11-16 19:53   ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221116152258.28772-1-skhan@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=devel@acpica.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robert.moore@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox