ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn
Subsystems (2)
PATCH 1/1 ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn
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.
--- drivers/acpi/acpica/utprint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/utprint.c +1 -1
@@ -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);
Signature · 1 line
2.34.1
Rafael J. Wysocki
maintainerQuoted 12 lines · Shuah Khan
utprint module is included in
tools/acpidumpand 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); | ~~~~~~~~~~~~~
Quoted 5 lines
Fix
sprintf()to use ACPI_UINT32_MAX/2 to get rid of the truncate problem. This change is inline othersprintf()implementations.If using
ACPI_UINT32_MAXis necessary in the kernel, acpidump might require special case to get rid of this truncate problem.
As ACPICA material, this should be submitted to the upstream project on GitHub and honestly I'm not sure if it is going to be resolved this way there.
Quoted 21 lines
Signed-off-by Shuah Khan <[email protected]>--- drivers/acpi/acpica/utprint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/acpi/acpica/utprint.c +1
-2@@ -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
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Shuah Khan
utprint module is included in
tools/acpidumpand 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 othersprintf()implementations.
Quoted 6 lines
Quoted 2 lines
If using
ACPI_UINT32_MAXis necessary in the kernel, acpidump might require special case to get rid of this truncate problem.As ACPICA material, this should be submitted to the upstream project on GitHub and honestly I'm not sure if it is going to be resolved this way there.
Thank you for your review. I will send this ACPICA upstream project.
thanks,
-- Shuah