]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
sysdeps: Implement _DBUS_DOUBLES_BITWISE_EQUAL with memcmp
authorSimon McVittie <smcv@collabora.com>
Wed, 16 Mar 2022 14:54:55 +0000 (14:54 +0000)
committerSimon McVittie <smcv@collabora.com>
Wed, 16 Mar 2022 14:54:55 +0000 (14:54 +0000)
memcmp is the Standard C way to compare arbitrary regions of memory
bit-by-bit, so let's use it, instead of reinventing it in a way that
violates Standard C aliasing rules.

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-sysdeps.h

index e7e36ad67f98a27dd10b97d2f49e9e5ef0cd3e42..95691c6911dbb266731d0f3f916778c685ca2664 100644 (file)
@@ -617,26 +617,12 @@ void _dbus_logv (DBusSystemLogSeverity  severity,
                  const char            *msg,
                  va_list args) _DBUS_GNUC_PRINTF (2, 0);
 
-/**
- * Casts a primitive C type to a byte array and then indexes
- * a particular byte of the array.
- */
-#define _DBUS_BYTE_OF_PRIMITIVE(p, i) \
-    (((const char*)&(p))[(i)])
 /** On x86 there is an 80-bit FPU, and if you do "a == b" it may have a
  * or b in an 80-bit register, thus failing to compare the two 64-bit
  * doubles for bitwise equality. So this macro compares the two doubles
  * bitwise.
  */
-#define _DBUS_DOUBLES_BITWISE_EQUAL(a, b)                                       \
-     (_DBUS_BYTE_OF_PRIMITIVE (a, 0) == _DBUS_BYTE_OF_PRIMITIVE (b, 0) &&       \
-      _DBUS_BYTE_OF_PRIMITIVE (a, 1) == _DBUS_BYTE_OF_PRIMITIVE (b, 1) &&       \
-      _DBUS_BYTE_OF_PRIMITIVE (a, 2) == _DBUS_BYTE_OF_PRIMITIVE (b, 2) &&       \
-      _DBUS_BYTE_OF_PRIMITIVE (a, 3) == _DBUS_BYTE_OF_PRIMITIVE (b, 3) &&       \
-      _DBUS_BYTE_OF_PRIMITIVE (a, 4) == _DBUS_BYTE_OF_PRIMITIVE (b, 4) &&       \
-      _DBUS_BYTE_OF_PRIMITIVE (a, 5) == _DBUS_BYTE_OF_PRIMITIVE (b, 5) &&       \
-      _DBUS_BYTE_OF_PRIMITIVE (a, 6) == _DBUS_BYTE_OF_PRIMITIVE (b, 6) &&       \
-      _DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7))
+#define _DBUS_DOUBLES_BITWISE_EQUAL(a, b) (memcmp (&(a), &(b), sizeof (double)) == 0)
 
 dbus_bool_t _dbus_get_autolaunch_address (const char *scope,
                                           DBusString *address,