unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: libc-alpha@sourceware.org
Subject: [PATCH] linux/sigsetops: fix type confusion (bug 31468)
Date: Mon, 11 Mar 2024 16:20:28 +0100	[thread overview]
Message-ID: <mvmle6ookw3.fsf@suse.de> (raw)

Each mask in the sigset array is a unsigned long, so fix __sigisemptyset
to use that instead of int.  The __sigword function returns a simple array
index, so it can return int instead of unsigned long.
---
 signal/tst-sigisemptyset.c                | 11 +++++++++++
 sysdeps/unix/sysv/linux/internal-sigset.h |  8 ++++----
 sysdeps/unix/sysv/linux/sigsetops.h       | 10 +++++-----
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/signal/tst-sigisemptyset.c b/signal/tst-sigisemptyset.c
index f5e35e8c22..11e7f39d09 100644
--- a/signal/tst-sigisemptyset.c
+++ b/signal/tst-sigisemptyset.c
@@ -89,6 +89,17 @@ do_test (void)
     TEST_COMPARE (sigisemptyset (&set), 1);
   }
 
+  {
+    sigset_t set;
+    for (int sig = 1; sig <= NSIG; sig++)
+      {
+	sigemptyset (&set);
+	if (sigaddset (&set, sig) < 0)
+	  continue;
+	TEST_COMPARE (sigisemptyset (&set), 0);
+      }
+  }
+
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/internal-sigset.h b/sysdeps/unix/sysv/linux/internal-sigset.h
index 3c21c3b6d5..5d7020b42d 100644
--- a/sysdeps/unix/sysv/linux/internal-sigset.h
+++ b/sysdeps/unix/sysv/linux/internal-sigset.h
@@ -54,7 +54,7 @@ static inline int
 internal_sigisemptyset (const internal_sigset_t *set)
 {
   int cnt = __NSIG_WORDS;
-  int ret = set->__val[--cnt];
+  unsigned long int ret = set->__val[--cnt];
   while (ret == 0 && --cnt >= 0)
     ret = set->__val[cnt];
   return ret == 0;
@@ -82,7 +82,7 @@ static inline int
 internal_sigismember (const internal_sigset_t *set, int sig)
 {
   unsigned long int mask = __sigmask (sig);
-  unsigned long int word = __sigword (sig);
+  int word = __sigword (sig);
   return set->__val[word] & mask ? 1 : 0;
 }
 
@@ -90,7 +90,7 @@ static inline void
 internal_sigaddset (internal_sigset_t *set, int sig)
 {
   unsigned long int mask = __sigmask (sig);
-  unsigned long int word = __sigword (sig);
+  int word = __sigword (sig);
   set->__val[word] |= mask;
 }
 
@@ -98,7 +98,7 @@ static inline void
 internal_sigdelset (internal_sigset_t *set, int sig)
 {
   unsigned long int mask = __sigmask (sig);
-  unsigned long int word = __sigword (sig);
+  int word = __sigword (sig);
   set->__val[word] &= ~mask;
 }
 
diff --git a/sysdeps/unix/sysv/linux/sigsetops.h b/sysdeps/unix/sysv/linux/sigsetops.h
index abd5576172..33db4f77b8 100644
--- a/sysdeps/unix/sysv/linux/sigsetops.h
+++ b/sysdeps/unix/sysv/linux/sigsetops.h
@@ -28,7 +28,7 @@
   (1UL << (((sig) - 1) % ULONG_WIDTH))
 
 /* Return the word index for SIG.  */
-static inline unsigned long int
+static inline int
 __sigword (int sig)
 {
   return (sig - 1) / ULONG_WIDTH;
@@ -66,7 +66,7 @@ static inline int
 __sigisemptyset (const sigset_t *set)
 {
   int cnt = __NSIG_WORDS;
-  int ret = set->__val[--cnt];
+  unsigned long int ret = set->__val[--cnt];
   while (ret == 0 && --cnt >= 0)
     ret = set->__val[cnt];
   return ret == 0;
@@ -92,7 +92,7 @@ static inline int
 __sigismember (const sigset_t *set, int sig)
 {
   unsigned long int mask = __sigmask (sig);
-  unsigned long int word = __sigword (sig);
+  int word = __sigword (sig);
   return set->__val[word] & mask ? 1 : 0;
 }
 
@@ -100,7 +100,7 @@ static inline void
 __sigaddset (sigset_t *set, int sig)
 {
   unsigned long int mask = __sigmask (sig);
-  unsigned long int word = __sigword (sig);
+  int word = __sigword (sig);
   set->__val[word] |= mask;
 }
 
@@ -108,7 +108,7 @@ static inline void
 __sigdelset (sigset_t *set, int sig)
 {
   unsigned long int mask = __sigmask (sig);
-  unsigned long int word = __sigword (sig);
+  int word = __sigword (sig);
   set->__val[word] &= ~mask;
 }
 
-- 
2.44.0


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

             reply	other threads:[~2024-03-11 15:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 15:20 Andreas Schwab [this message]
2024-03-11 18:30 ` [PATCH] linux/sigsetops: fix type confusion (bug 31468) Florian Weimer

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

  List information: https://www.gnu.org/software/libc/involved.html

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

  git send-email \
    --in-reply-to=mvmle6ookw3.fsf@suse.de \
    --to=schwab@suse.de \
    --cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).