]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
_dbus_string_test(): Fix fatal build error caused by "-Wstrict-aliasing"
authorRalf Habacker <ralf.habacker@freenet.de>
Tue, 1 Mar 2022 09:54:05 +0000 (10:54 +0100)
committerSimon McVittie <smcv@collabora.com>
Thu, 21 Apr 2022 12:55:38 +0000 (13:55 +0100)
To fix this problem, the problematic code was replaced by a new function
_dbus_string_get_allocated_size(), which uses the existing macro
DBUS_CONST_STRING_PREAMBLE for these purposes.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-string.c
dbus/dbus-string.h
test/internals/dbus-string-util.c

index 529a099e64b7ce7433d7e989df2eeacb91562ad1..9c917cd90ec09bb14fdcfa70768645fc860046b7 100644 (file)
@@ -466,6 +466,20 @@ open_gap (int             len,
   return TRUE;
 }
 
+/**
+ * Returns the allocated size of the string
+ *
+ * @param str the string
+ * @returns the allocated size
+ */
+int
+_dbus_string_get_allocated_size (const DBusString *str)
+{
+  DBUS_CONST_STRING_PREAMBLE (str);
+
+  return real->allocated;
+}
+
 #ifndef _dbus_string_get_data
 /**
  * Gets the raw character buffer from the string.  The returned buffer
index ff81102c69b1c784499210dff39c088391a8446a..b75da1aa30ad5ee742b5140c24c1e827f217ba0e 100644 (file)
@@ -105,6 +105,8 @@ void          _dbus_string_lock                  (DBusString        *str);
 DBUS_PRIVATE_EXPORT
 dbus_bool_t   _dbus_string_compact               (DBusString        *str,
                                                   int                max_waste);
+DBUS_PRIVATE_EXPORT
+int           _dbus_string_get_allocated_size    (const DBusString *str);
 #ifndef _dbus_string_get_data
 DBUS_PRIVATE_EXPORT
 char*         _dbus_string_get_data              (DBusString        *str);
index b2af6ca37f98693aa0509f15a544ad6839790e3d..b4a3aa6878671052512a5f61f684a35dab04c113 100644 (file)
@@ -746,7 +746,7 @@ _dbus_string_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
       _dbus_test_fatal ("failed to compact after set_length");
 
     /* peek inside to make sure it worked */
-    if (((DBusRealString *)&str)->allocated > 30)
+    if (_dbus_string_get_allocated_size (&str) > 30)
       _dbus_test_fatal ("compacting string didn't do anything");
 
     if (!_dbus_string_equal_c_str (&str, "abcdefghij"))