From: Thorsten Glaser <tg@evolvis.org>
To: musl@lists.openwall.com
Cc: lihua.zhao.cn@windriver.com
Subject: Re: [musl] [PATCH] set EINVAL for sigismember when sig is invalid
Date: Tue, 29 Oct 2024 14:12:49 +0100 (CET) [thread overview]
Message-ID: <63e3ced1-1b7d-8427-0105-a865d21f7e6f@evolvis.org> (raw)
In-Reply-To: <20241029130234.729799-1-lihua.zhao.cn@windriver.com>
On Tue, 29 Oct 2024, lihua.zhao.cn@windriver.com wrote:
> int sigismember(const sigset_t *set, int sig)
> {
> unsigned s = sig-1;
>- if (s >= _NSIG-1) return 0;
>+ if (s < 0 || s >= _NSIG-1) {
unsigned s can never be 0, and assignment from int will wrap around,
so the >= is enough.
There’s UB if sig == INT_MIN though.
- unsigned s = sig-1;
+ unsigned s = sig;
+ ++s;
Or:
- unsigned s = sig-1;
+ unsigned s = (unsigned)sig - 1U;
bye,
//mirabilos
--
In traditional syntax ' is ignored, but in c99 everything between two ' is
handled as character constant. Therefore you cannot use ' in a preproces-
sing file in c99 mode. -- Ragge
No faith left in ISO C99, undefined behaviour, etc.
next prev parent reply other threads:[~2024-10-29 13:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 13:02 lihua.zhao.cn
2024-10-29 13:12 ` Thorsten Glaser [this message]
2024-10-29 20:26 ` Rich Felker
2024-10-30 3:07 ` [musl] [PATCH v2] signal: " lihua.zhao.cn
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=63e3ced1-1b7d-8427-0105-a865d21f7e6f@evolvis.org \
--to=tg@evolvis.org \
--cc=lihua.zhao.cn@windriver.com \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).