Smatch (Semantic Matching Tool) development
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Cc: smatch@vger.kernel.org
Subject: Re: Build problem smatch 1.75
Date: Mon, 4 May 2026 11:20:20 +0300	[thread overview]
Message-ID: <afhWxKZ-F644-cBp@stanley.mountain> (raw)
In-Reply-To: <e8f14631-b01b-4285-8598-acad42c901be@oracle.com>

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 <error27@gmail.com>
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 <error27@gmail.com>
---
 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


  reply	other threads:[~2026-05-04  8:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04  7:55 Build problem smatch 1.75 Harshit Mogalapalli
2026-05-04  8:20 ` Dan Carpenter [this message]
2026-05-04 10:47   ` Harshit Mogalapalli
2026-05-05 10:41     ` Dan Carpenter
2026-05-05 14:58       ` Harshit Mogalapalli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afhWxKZ-F644-cBp@stanley.mountain \
    --to=error27@gmail.com \
    --cc=harshit.m.mogalapalli@oracle.com \
    --cc=smatch@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox