[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix src/function.c build failure on gcc-12.
From: |
Sergei Trofimovich |
Subject: |
[PATCH] Fix src/function.c build failure on gcc-12. |
Date: |
Fri, 18 Feb 2022 23:48:13 +0000 |
From: Sergei Trofimovich <siarheit@google.com>
Upcoming gcc-12 detects possible buffer overflow for 1 byte:
src/function.c: In function 'func_call':
src/function.c:2781:24: error: '__builtin___sprintf_chk' may write a
terminating nul past the end of the destination [-Werror=format-overflow=8]
2781 | sprintf (num, "%d", i);
| ^
In file included from glibc-2.35-dev/include/stdio.h:894,
from src/makeint.h:89,
from src/function.c:17:
In function 'sprintf',
inlined from 'func_call' at src/function.c:2781:7:
glibc-2.35-dev/include/bits/stdio2.h:38:10: note: '__builtin___sprintf_chk'
output between 2 and 12 bytes into a destination of size 11
Unlikely numbers like '-1234567890' including null terminator take 12
bytes of storage.
* src/function.c: Allocate enough storage for num
---
src/function.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/function.c b/src/function.c
index 9add8f65..af2095da 100644
--- a/src/function.c
+++ b/src/function.c
@@ -2776,7 +2776,7 @@ func_call (char *o, char **argv, const char *funcname
UNUSED)
for (; i < max_args; ++i)
{
- char num[11];
+ char num[12];
sprintf (num, "%d", i);
define_variable (num, strlen (num), "", o_automatic, 0);
--
2.35.1
- [PATCH] Fix src/function.c build failure on gcc-12.,
Sergei Trofimovich <=