From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: sparse regex error
Date: Wed, 20 Dec 2023 00:18:11 +0000 [thread overview]
Message-ID: <6f853a6b-9ac3-4bfd-a968-89d43fbcce2a@ramsayjones.plus.com> (raw)
Hi Luc,
Long time no hear! ;)
About 18 months ago, I updated my Linux installation and sparse started
to fail when run during my git build. The reason for the failure was,
ultimately, a change to the 'regex.h' header file as a result of the
update from one Ubuntu LTS base to the current Ubuntu LTS base.
In particular, an update to the libc6-devel package from 2.31 to 2.35
which (in part) looked like this:
.
524a525,548
> #ifndef _REGEX_NELTS
> # if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
> && !defined __STDC_NO_VLA__)
> # define _REGEX_NELTS(n) n
> # else
> # define _REGEX_NELTS(n)
> # endif
> #endif
>
.
645c681,682
< regmatch_t __pmatch[_Restrict_arr_],
---
> regmatch_t __pmatch[_Restrict_arr_
> _REGEX_NELTS (__nmatch)],
.
The last hunk is the declaration of regexec(), thus:
extern int regexec (const regex_t *_Restrict_ __preg,
const char *_Restrict_ __String, size_t __nmatch,
regmatch_t __pmatch[_Restrict_arr_
_REGEX_NELTS (__nmatch)],
int __eflags);
To fix my build, I added the following to my config.mak file on linux:
SPARSE_FLAGS += -D__STDC_NO_VLA__
. and immediately started working on a fix to sparse! Oh wait ... :)
I did report the problem and the above workaround on the git ML [1], and
created a test in my sparse repo to demonstrate the problem, thus:
$ git diff
diff --git a/validation/restrict-array.c b/validation/restrict-array.c
index 04bfdad9..86753b7d 100644
--- a/validation/restrict-array.c
+++ b/validation/restrict-array.c
@@ -29,9 +29,19 @@ typedef unsigned long int size_t;
extern int regexec (const regex_t *__restrict __preg,
const char *__restrict __string, size_t __nmatch,
- regmatch_t __pmatch[__restrict_arr],
+ regmatch_t __pmatch[__restrict_arr __nmatch],
int __eflags);
+static int call_regexec(const regex_t *r)
+{
+ char s[] = "something to search";
+ regmatch_t pm[5];
+
+ if (regexec(r, s, 5, pm, 0))
+ return 0;
+ return 1;
+}
+
/*
* check-name: restrict array attribute
*/
$
which, similarly to git, shows errors not on the declaration of the
regexec() function, but on each call site (about a dozen in git):
$ ./sparse validation/restrict-array.c
validation/restrict-array.c:32:56: error: undefined identifier '__nmatch'
validation/restrict-array.c:32:56: error: bad constant expression type
$
I have tried to find the time, in the last couple of days, to take a look
and find a fix for this, but I have had to admit defeat and just content
myself with noting the problem here. :(
Maybe I will find some time over the xmas break.
[1] https://lore.kernel.org/git/7498bff0-782f-8c81-5817-ed841f12dbba@ramsayjones.plus.com/
ATB,
Ramsay Jones
next reply other threads:[~2023-12-20 0:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 0:18 Ramsay Jones [this message]
2023-12-20 23:13 ` sparse regex error Luc Van Oostenryck
2023-12-21 1:45 ` Ramsay Jones
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=6f853a6b-9ac3-4bfd-a968-89d43fbcce2a@ramsayjones.plus.com \
--to=ramsay@ramsayjones.plus.com \
--cc=linux-sparse@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).