[PATCH] fix error -Werror=stringop-truncation with gcc-15

0 views
Skip to first unread message

Quirin Gylstorff

unread,
Sep 8, 2025, 4:36:00 AM (yesterday) Sep 8
to efibootg...@googlegroups.com, jan.k...@siemens.com
From: Quirin Gylstorff <quirin.g...@siemens.com>

This fixes the following error with gcc-15:

In function 'bgenv_get_uint',
inlined from 'bgenv_get' at env/env_api_fat.c:360:10:
env/env_api_fat.c:296:9: error: 'strncpy' output may be truncated copying between 2 and 4 bytes from a string of length 254 [-Werror=stringop-truncation]
296 | strncpy(data, buffer, res+1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

As sprintf adds already a null-terminator and data is a void pointer
we can use memcpy directly.

Signed-off-by: Quirin Gylstorff <quirin.g...@siemens.com>
---
env/env_api_fat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 7c84dc6..b409d45 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -293,7 +293,7 @@ static int bgenv_get_uint(char *buffer, uint64_t *type, void *data,
if (!data) {
return res+1;
}
- strncpy(data, buffer, res+1);
+ memcpy(data, buffer, res+1);
if (type) {
*type = t;
}
--
2.50.1

Jan Kiszka

unread,
Sep 8, 2025, 6:30:41 AM (yesterday) Sep 8
to Quirin Gylstorff, efibootg...@googlegroups.com
Thanks, applied.

The APIs of bgenv_get_uint/string need some refactoring, independently
of this...

Jan

--
Siemens AG, Foundational Technologies
Linux Expert Center
Reply all
Reply to author
Forward
0 new messages