* [PATCH] ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn
@ 2022-11-16 15:22 Shuah Khan
2022-11-16 19:05 ` Rafael J. Wysocki
0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2022-11-16 15:22 UTC (permalink / raw)
To: robert.moore, rafael.j.wysocki, lenb
Cc: Shuah Khan, linux-acpi, devel, linux-kernel
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn
2022-11-16 15:22 [PATCH] ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn Shuah Khan
@ 2022-11-16 19:05 ` Rafael J. Wysocki
2022-11-16 19:53 ` Shuah Khan
0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2022-11-16 19:05 UTC (permalink / raw)
To: Shuah Khan
Cc: robert.moore, rafael.j.wysocki, lenb, linux-acpi, devel,
linux-kernel
On Wed, Nov 16, 2022 at 4:23 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>
> 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.
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.
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn
2022-11-16 19:05 ` Rafael J. Wysocki
@ 2022-11-16 19:53 ` Shuah Khan
0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2022-11-16 19:53 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: robert.moore, rafael.j.wysocki, lenb, linux-acpi, devel,
linux-kernel, Shuah Khan
On 11/16/22 12:05, Rafael J. Wysocki wrote:
> On Wed, Nov 16, 2022 at 4:23 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>>
>> 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.
>
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-16 19:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-16 15:22 [PATCH] ACPICA: Fix sprintf() INT_MAX -Wformat-truncation= warn Shuah Khan
2022-11-16 19:05 ` Rafael J. Wysocki
2022-11-16 19:53 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox