Re: Build problem smatch 1.75
Dan Carpenter <[email protected]> Mon, 4 May 2026 11:20:20 +0300
| Newsgroups | org.kernel.vger.smatch |
|---|---|
| Message-ID | <[email protected]> |
On Mon, May 04, 2026 at 01:25:43PM +0530, Harshit Mogalapalli wrote:
> Hi Dan,
>
> Build error:
>
> pre-process.c: In function ‘parse_expansion’:
> pre-process.c:1648:16: error: variable-sized object may not be initialized
> 1648 | struct arg_state args[slots] = {};
> | ^~~~~~~~~
What compiler are you using? This is a bug in Sparse. We should
probably fix it there.
Apparently you can't use variable length arrays with an initializer.
Why do C compilers have to suck? They should have made an exception for
memset to zero.
> pre-process.c: In function ‘find_include’:
> pre-process.c:1015:56: warning: ‘%s’ directive output may be truncated
> writing up to 255 bytes into a region of size between 1 and 4096
> [-Wformat-truncation=]
> 1015 | snprintf(buf, sizeof(buf), "%s/%s", cwd,
> entry->d_name);
> | ^~
> pre-process.c:1015:25: note: ‘snprintf’ output between 2 and 4352 bytes into
> a destination of size 4097
> 1015 | snprintf(buf, sizeof(buf), "%s/%s", cwd,
> entry->d_name);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> I think the problem is introduced by:
>
> Fixes: 1a9a98e3c7b8 ("__VA_OPT__: parsing")
>
> I think we need a memset() in parse_expansion()
The snprintf() warnings are my fault but I hate that warning. I don't
care if the snprintf() truncates... Truncating is the whole reason that
I use it... Anyway, sure let me silence that.
regards,
dan carpenter
From bcc58b9ccf06d28ab6be4f0992bc74f462aa12f8 Mon Sep 17 00:00:00 2001
From: Dan Carpenter <[email protected]>
Date: Mon, 4 May 2026 11:16:24 +0300
Subject: [PATCH] pre-process: silence a -Wformat-truncation warning
Add a check for snprintf() overflows to make GCC happy.
Signed-off-by: Dan Carpenter <[email protected]>
---
pre-process.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/pre-process.c b/pre-process.c
index d9a0a9e73a73..fdcc29338c94 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -1012,7 +1012,11 @@ const char *find_include(const char *skip, const char *look_for)
lstat(entry->d_name, &statbuf);
if (strcmp(entry->d_name, look_for) == 0) {
- snprintf(buf, sizeof(buf), "%s/%s", cwd, entry->d_name);
+ int cnt;
+
+ cnt = snprintf(buf, sizeof(buf), "%s/%s", cwd, entry->d_name);
+ if (cnt >= sizeof(buf))
+ return NULL;
closedir(dp);
return buf;
}
--
2.53.0