# Fix sigaddset/sigdelset bit-fiddling math · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/4b63f94b4ecf282c259c24a09d6c4ab7490b6cab)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 4b63f94b4ecf282c259c24a09d6c4ab7490b6cab

Requested commit: 4b63f94b4ecf282c259c24a09d6c4ab7490b6cab

Commit: 4b63f94b4ecf282c259c24a09d6c4ab7490b6cab

Tree: f003b1365d4138476c415be6d9a1739f237ef60b

Author: Pat Tullmann

Committer: Alex Rønne Petersen

## Message

```
Fix sigaddset/sigdelset bit-fiddling math

The code was using u32 and usize interchangably, which doesn't work on
64-bit systems.  This:
  `pub const sigset_t = [1024 / 32]u32;`
is not consistent with this:
  `const shift = @as(u5, @intCast(s & (usize_bits - 1)));`

However, normal signal numbers are less than 31, so the bad math doesn't matter much.  Also, despite support for 1024 signals in the set, only setting signals between 1 and NSIG (which is mostly 65, but sometimes 128) is defined.  The existing tests only exercised signal numbers in the first 31 bits so they didn't trip over this:

The C library `sigaddset` will return `EINVAL` if given an out of bounds signal number.  I made the Zig code just silently ignore any out of bounds signal numbers.

Moved all the `sigset` related declarations next to each in the source, too.

The `filled_sigset` seems non-standard to me.  I think it is meant to be used like `empty_sigset`, but it only contains 31 set signals, which seems wrong (should be 64 or 128, aka `NSIG`).  It's also unused.  The oddly named but similar `all_mask` is used (by posix.zig) but sets all 1024 bits (which I understood to be undefined behavior but seems to work just fine).  For comparison the musl `sigfillset` fills in 65 bits or 128 bits.

```

## Parents

- [a9ff2d56ceccd545c9659b8c2768dbeeaa25dca4](https://git.cafe/gitcafe/zig/commit/a9ff2d56ceccd545c9659b8c2768dbeeaa25dca4?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/4b63f94b4ecf282c259c24a09d6c4ab7490b6cab?format=markdown)
