Commit graph

9 commits

Author SHA1 Message Date
Peter Hutterer
aa9d5bf630 util: silence two clang-tidy false positives
Both about the same complaint, somehow it is of the impression that
masks->mask can be an uninitialized value. The only place where we
allocate those is in _infmask_ensure_size() and they're set to zero
there.

libinput/src/util-bits.h:166:22: warning: The left operand of '&' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
  166 |         return !!(mask.mask & bit(bit));
      |                             ^
libinput/src/util-bits.h:444:2: note: Calling 'infmask_set_bit'
  444 |         infmask_set_bit(&m, mask);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~
libinput/src/util-bits.h:394:15: note: Calling 'infmask_bit_is_set'
  394 |         bool isset = infmask_bit_is_set(mask, bit);
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libinput/src/util-bits.h:382:13: note: Field 'mask' is non-null
  382 |         if (!mask->mask || bit / bitmask_size() >= mask->nmasks)
      |                    ^
libinput/src/util-bits.h:382:6: note: Left side of '||' is false
  382 |         if (!mask->mask || bit / bitmask_size() >= mask->nmasks)
      |             ^
libinput/src/util-bits.h:382:2: note: Taking false branch
  382 |         if (!mask->mask || bit / bitmask_size() >= mask->nmasks)
      |         ^
libinput/src/util-bits.h:385:9: note: Uninitialized value stored to 'mask.mask'
  385 |         return bitmask_bit_is_set(mask->mask[bit / bitmask_size()], // NOLINT(core.UndefinedBinaryOperatorResult)
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  386 |                                   bit % bitmask_size());
      |                                   ~~~~~~~~~~~~~~~~~~~~~
libinput/src/util-bits.h:385:9: note: Calling 'bitmask_bit_is_set'
  385 |         return bitmask_bit_is_set(mask->mask[bit / bitmask_size()], // NOLINT(core.UndefinedBinaryOperatorResult)
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  386 |                                   bit % bitmask_size());
      |                                   ~~~~~~~~~~~~~~~~~~~~~
libinput/src/util-bits.h:166:22: note: The left operand of '&' is a garbage value
  166 |         return !!(mask.mask & bit(bit));
      |                   ~~~~~~~~~ ^

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1292>
2025-08-06 07:34:55 +00:00
Peter Hutterer
b831068fbb util: annotate that our mask cannot be NULL
Poor clang-tidy thinks that there's a code-path here that lets us
return with a NULL mask.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1292>
2025-08-06 07:34:55 +00:00
Peter Hutterer
a102269364 util: mark the various bitmask functions as nonnull
Might as well get a bit of compiler help here.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1292>
2025-08-06 07:34:54 +00:00
Peter Hutterer
d45f4493f1 util: add an infmask_t type for an infinitely-sized bitmask
Using the bitmask-size underneath but this mask can grow to any number
of bits requested. Notably, the sized of the mask is the nearest 4-byte
multiple for the highest bit ever set in the mask.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1271>
2025-08-01 14:29:44 +10:00
Peter Hutterer
4c4d5f33ee util: add bitmask_size() to return the size of a bitmask
This way we can theoretically change the bitmask to use a longer type in
the future.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1271>
2025-08-01 14:29:44 +10:00
Peter Hutterer
2a1095924b Run clang-format over the code
This uses the .clang-format file in the follow-up commit, but committed
prior to that to ease review of said file and various integrations.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1246>
2025-07-01 16:42:44 +10:00
Peter Hutterer
8974a15178 util: add a bitmask_t type for bit masks
Previously we used uint32_t for bitmasks but having a custom type means
we're less likely to confuse an int value with a mask type.

Two types of API here, the u32 api for passing in masks and a bit API
for passing in single bits.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1218>
2025-06-18 19:38:14 +10:00
Peter Hutterer
a5dd45e8ce Remove duplicate empty lines in our source
We only touch src and tools, imported headers from include are not ours
to change.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-25 10:08:20 +10:00
Peter Hutterer
c84366e85e Split utility functions into separate source files
libinput-util.h is getting a bit of a catchall bucket and it includes things
like libinput-private.h which in turn includes libwacom. This makes
libinput-util.h less useful for bits that only need e.g. the string processing
utilities.

So let's split them all up in to separate files, to be used as-needed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-09-11 12:23:04 +10:00