From: Ralf Habacker Date: Tue, 1 Mar 2022 09:54:05 +0000 (+0100) Subject: _dbus_string_test(): Fix fatal build error caused by "-Wstrict-aliasing" X-Git-Tag: dbus-1.15.0~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21a6441f33bcf8cc7749af3d0d1dfc874e4a5c99;p=thirdparty%2Fdbus.git _dbus_string_test(): Fix fatal build error caused by "-Wstrict-aliasing" 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 Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275 Reviewed-by: Simon McVittie --- diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index 529a099e6..9c917cd90 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -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 diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h index ff81102c6..b75da1aa3 100644 --- a/dbus/dbus-string.h +++ b/dbus/dbus-string.h @@ -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); diff --git a/test/internals/dbus-string-util.c b/test/internals/dbus-string-util.c index b2af6ca37..b4a3aa687 100644 --- a/test/internals/dbus-string-util.c +++ b/test/internals/dbus-string-util.c @@ -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"))