diff mbox

acpi: method: work around some gcc madness (LP: #1687056)

Message ID 20170428162602.12397-1-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King April 28, 2017, 4:26 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

acpi/method/method.c:6197:36: error: 'snprintf' output may be
truncated before the last format character [-Werror=format-truncation=]
   snprintf(buffer, sizeof(buffer), "_AC%d", i);
                                    ^~~~~~~
acpi/method/method.c:6197:3: note: 'snprintf' output between 5
and 6 bytes into a destination of size 5
   snprintf(buffer, sizeof(buffer), "_AC%d", i);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add some extra slack in the target buffer and also specify %1d rather
than %d.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/method/method.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Alex Hung April 28, 2017, 4:43 p.m. UTC | #1
On 2017-04-28 09:26 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> acpi/method/method.c:6197:36: error: 'snprintf' output may be
> truncated before the last format character [-Werror=format-truncation=]
>    snprintf(buffer, sizeof(buffer), "_AC%d", i);
>                                     ^~~~~~~
> acpi/method/method.c:6197:3: note: 'snprintf' output between 5
> and 6 bytes into a destination of size 5
>    snprintf(buffer, sizeof(buffer), "_AC%d", i);
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Add some extra slack in the target buffer and also specify %1d rather
> than %d.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/method/method.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index d276b767..61427ec1 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -2879,7 +2879,7 @@ static int method_test_PS0(fwts_framework *fw)
>  		int i;
>
>  		for (i = 1; i < 4; i++) {
> -			char name[5];
> +			char name[6];
>
>  			snprintf(name, sizeof(name), "_PS%1d", i);
>  			if (fwts_acpi_object_exists(name) != NULL) {
> @@ -6192,9 +6192,9 @@ static int method_test_ACx(fwts_framework *fw)
>  	int i;
>
>  	for (i = 0; i < 10; i++) {
> -		char buffer[5];
> +		char buffer[6];
>
> -		snprintf(buffer, sizeof(buffer), "_AC%d", i);
> +		snprintf(buffer, sizeof(buffer), "_AC%1d", i);
>  		method_evaluate_method(fw, METHOD_OPTIONAL,
>  			buffer, NULL, 0, method_test_THERM_return, buffer);
>  		fwts_log_nl(fw);
>


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu May 4, 2017, 8:05 a.m. UTC | #2
On 04/29/2017 12:26 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> acpi/method/method.c:6197:36: error: 'snprintf' output may be
> truncated before the last format character [-Werror=format-truncation=]
>    snprintf(buffer, sizeof(buffer), "_AC%d", i);
>                                     ^~~~~~~
> acpi/method/method.c:6197:3: note: 'snprintf' output between 5
> and 6 bytes into a destination of size 5
>    snprintf(buffer, sizeof(buffer), "_AC%d", i);
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Add some extra slack in the target buffer and also specify %1d rather
> than %d.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/method/method.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index d276b767..61427ec1 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -2879,7 +2879,7 @@ static int method_test_PS0(fwts_framework *fw)
>  		int i;
>
>  		for (i = 1; i < 4; i++) {
> -			char name[5];
> +			char name[6];
>
>  			snprintf(name, sizeof(name), "_PS%1d", i);
>  			if (fwts_acpi_object_exists(name) != NULL) {
> @@ -6192,9 +6192,9 @@ static int method_test_ACx(fwts_framework *fw)
>  	int i;
>
>  	for (i = 0; i < 10; i++) {
> -		char buffer[5];
> +		char buffer[6];
>
> -		snprintf(buffer, sizeof(buffer), "_AC%d", i);
> +		snprintf(buffer, sizeof(buffer), "_AC%1d", i);
>  		method_evaluate_method(fw, METHOD_OPTIONAL,
>  			buffer, NULL, 0, method_test_THERM_return, buffer);
>  		fwts_log_nl(fw);
>


Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
index d276b767..61427ec1 100644
--- a/src/acpi/method/method.c
+++ b/src/acpi/method/method.c
@@ -2879,7 +2879,7 @@  static int method_test_PS0(fwts_framework *fw)
 		int i;
 
 		for (i = 1; i < 4; i++) {
-			char name[5];
+			char name[6];
 
 			snprintf(name, sizeof(name), "_PS%1d", i);
 			if (fwts_acpi_object_exists(name) != NULL) {
@@ -6192,9 +6192,9 @@  static int method_test_ACx(fwts_framework *fw)
 	int i;
 
 	for (i = 0; i < 10; i++) {
-		char buffer[5];
+		char buffer[6];
 
-		snprintf(buffer, sizeof(buffer), "_AC%d", i);
+		snprintf(buffer, sizeof(buffer), "_AC%1d", i);
 		method_evaluate_method(fw, METHOD_OPTIONAL,
 			buffer, NULL, 0, method_test_THERM_return, buffer);
 		fwts_log_nl(fw);