]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-internals: use size_t in _DBUS_ALIGN_VALUE()
authorAlex Richardson <arichardson@FreeBSD.org>
Fri, 12 Aug 2022 10:18:05 +0000 (10:18 +0000)
committerSimon McVittie <smcv@collabora.com>
Wed, 21 Sep 2022 11:35:05 +0000 (11:35 +0000)
When targeting CHERI-enabled architectures such as Arm Morello, performing
a bitwise and with uintptr_t values can result in an ambiguous operation
compiler warning. Fix this warning by telling  compiler which operand is
(potentially) a pointer and which one is an integer by changing the
boundary type to size_t. This change has no functional effect on other
architectures but is required to build with -Werror for Morello.

Example warning message:
```
warning: binary expression on capability types 'unsigned __intcap' and 'unsigned __intcap'; it is not clear which should be used as the source of provenance; currently provenance is inherited from the left-hand side [-Wcheri-provenance]
  _dbus_assert (_DBUS_ALIGN_VALUE (insert_at, 8) == (unsigned) insert_at);
```

dbus/dbus-internals.h

index c7967d241feb8455d029d0e8f28eabc6094c4258..deee366f576c03f9bf38122d6828908a51031ee5 100644 (file)
@@ -277,7 +277,8 @@ _dbus_assert_error_xor_bool (const DBusError *error,
  */
 
 #define _DBUS_ALIGN_VALUE(this, boundary) \
-  (( ((uintptr_t)(this)) + (((uintptr_t)(boundary)) -1)) & (~(((uintptr_t)(boundary))-1)))
+  ((((uintptr_t) (this)) + (((size_t) (boundary)) - 1)) & \
+   (~(((size_t) (boundary)) - 1)))
 
 #define _DBUS_ALIGN_ADDRESS(this, boundary) \
   ((void*)_DBUS_ALIGN_VALUE(this, boundary))