int _dbus_string_get_length (const DBusString *str);
#endif /* !_dbus_string_get_length */
+/**
+ * Get the string's length as an unsigned integer, for comparison with
+ * size_t and similar unsigned types that does not trigger compiler
+ * warnings about potential value changes during conversion.
+ *
+ * DBusString lengths are signed for historical reasons, but we know that
+ * the length is always >= 0 (and DBUS_GENERIC_STRING_PREAMBLE asserts
+ * that this is the case) so we know that this cast does not change the
+ * value.
+ */
+static inline unsigned int
+_dbus_string_get_length_uint (const DBusString *str)
+{
+ return (unsigned int) _dbus_string_get_length (str);
+}
+
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_lengthen (DBusString *str,
int additional_length);
_dbus_verbose ("getsockopt failed with %s, len now %lu\n",
_dbus_strerror (e), (unsigned long) len);
- if (e != ERANGE || len <= _dbus_string_get_length (&buf))
+ if (e != ERANGE || len <= _dbus_string_get_length_uint (&buf))
{
_dbus_verbose ("Failed to getsockopt(SO_PEERSEC): %s\n",
_dbus_strerror (e));
goto out;
}
- if (len > _dbus_string_get_length (&buf))
+ if (len > _dbus_string_get_length_uint (&buf))
{
- _dbus_verbose ("%lu > %d", (unsigned long) len,
- _dbus_string_get_length (&buf));
+ _dbus_verbose ("%lu > %u", (unsigned long) len,
+ _dbus_string_get_length_uint (&buf));
_dbus_assert_not_reached ("getsockopt(SO_PEERSEC) overflowed");
}