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

Colin King colin.king at canonical.com
Fri Apr 28 16:26:02 UTC 2017


From: Colin Ian King <colin.king at 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 at 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);
-- 
2.11.0




More information about the fwts-devel mailing list