From 62dd25a450fecb1d1530b81932969738ea3b64d1 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 23 Nov 2015 18:46:51 +0100 Subject: [PATCH 1/2] Fix warning: "pointer targets in assignment differ in signedness [-Wpointer-sign]". The warnings are fixed by adding functions to dbus string name space returning unsigned char pointer, which avoids the need to use casts. Bug: https://bugs.freedesktop.org/attachment.cgi?id=93069 --- dbus/dbus-address.c | 2 +- dbus/dbus-marshal-basic.c | 14 ++++++++++---- dbus/dbus-marshal-byteswap.c | 2 +- dbus/dbus-marshal-header.c | 4 ++-- dbus/dbus-marshal-recursive.c | 14 +++++++------- dbus/dbus-marshal-validate.c | 16 ++++++++-------- dbus/dbus-string.h | 18 ++++++++++++++++++ tools/dbus-spam.c | 2 +- 8 files changed, 48 insertions(+), 24 deletions(-) diff --git a/dbus/dbus-address.c b/dbus/dbus-address.c index c4cfbbe..23f9268 100644 --- a/dbus/dbus-address.c +++ b/dbus/dbus-address.c @@ -112,7 +112,7 @@ _dbus_address_append_escaped (DBusString *escaped, ret = FALSE; orig_len = _dbus_string_get_length (escaped); - p = (const unsigned char *) _dbus_string_get_const_data (unescaped); + p = _dbus_string_get_const_udata (unescaped); end = p + _dbus_string_get_length (unescaped); while (p != end) { diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c index bd4f968..334e7a8 100644 --- a/dbus/dbus-marshal-basic.c +++ b/dbus/dbus-marshal-basic.c @@ -1610,11 +1610,17 @@ _dbus_marshal_test (void) int pos, dump_pos; unsigned char array1[5] = { 3, 4, 0, 1, 9 }; dbus_int16_t array2[3] = { 124, 457, 780 }; + dbus_uint16_t array2u[3] = { 124, 457, 780 }; dbus_int32_t array4[3] = { 123, 456, 789 }; + dbus_uint32_t array4u[3] = { 123, 456, 789 }; dbus_int64_t array8[3] = { DBUS_INT64_CONSTANT (0x123ffffffff), DBUS_INT64_CONSTANT (0x456ffffffff), DBUS_INT64_CONSTANT (0x789ffffffff) }; + dbus_uint64_t array8u[3] = { DBUS_UINT64_CONSTANT (0x123ffffffff), + DBUS_UINT64_CONSTANT (0x456ffffffff), + DBUS_UINT64_CONSTANT (0x789ffffffff) }; dbus_int64_t *v_ARRAY_INT64; + dbus_int64_t *v_ARRAY_UINT64; unsigned char *v_ARRAY_BYTE; dbus_int16_t *v_ARRAY_INT16; dbus_uint16_t *v_ARRAY_UINT16; @@ -1707,13 +1713,13 @@ _dbus_marshal_test (void) /* Arrays */ MARSHAL_TEST_FIXED_ARRAY (INT16, DBUS_BIG_ENDIAN, array2); MARSHAL_TEST_FIXED_ARRAY (INT16, DBUS_LITTLE_ENDIAN, array2); - MARSHAL_TEST_FIXED_ARRAY (UINT16, DBUS_BIG_ENDIAN, array2); - MARSHAL_TEST_FIXED_ARRAY (UINT16, DBUS_LITTLE_ENDIAN, array2); + MARSHAL_TEST_FIXED_ARRAY (UINT16, DBUS_BIG_ENDIAN, array2u); + MARSHAL_TEST_FIXED_ARRAY (UINT16, DBUS_LITTLE_ENDIAN, array2u); MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_BIG_ENDIAN, array4); MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_LITTLE_ENDIAN, array4); - MARSHAL_TEST_FIXED_ARRAY (UINT32, DBUS_BIG_ENDIAN, array4); - MARSHAL_TEST_FIXED_ARRAY (UINT32, DBUS_LITTLE_ENDIAN, array4); + MARSHAL_TEST_FIXED_ARRAY (UINT32, DBUS_BIG_ENDIAN, array4u); + MARSHAL_TEST_FIXED_ARRAY (UINT32, DBUS_LITTLE_ENDIAN, array4u); MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_BIG_ENDIAN, array1); MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_LITTLE_ENDIAN, array1); diff --git a/dbus/dbus-marshal-byteswap.c b/dbus/dbus-marshal-byteswap.c index 43a4f47..27695aa 100644 --- a/dbus/dbus-marshal-byteswap.c +++ b/dbus/dbus-marshal-byteswap.c @@ -239,7 +239,7 @@ _dbus_marshal_byteswap (const DBusString *signature, byteswap_body_helper (&reader, TRUE, old_byte_order, new_byte_order, - (unsigned char *) _dbus_string_get_data_len (value_str, value_pos, 0), + _dbus_string_get_udata_len (value_str, value_pos, 0), NULL); } diff --git a/dbus/dbus-marshal-header.c b/dbus/dbus-marshal-header.c index 48151c6..74b39cd 100644 --- a/dbus/dbus-marshal-header.c +++ b/dbus/dbus-marshal-header.c @@ -1460,7 +1460,7 @@ _dbus_header_toggle_flag (DBusHeader *header, { unsigned char *flags_p; - flags_p = _dbus_string_get_data_len (&header->data, FLAGS_OFFSET, 1); + flags_p = _dbus_string_get_udata_len (&header->data, FLAGS_OFFSET, 1); if (value) *flags_p |= flag; @@ -1481,7 +1481,7 @@ _dbus_header_get_flag (DBusHeader *header, { const unsigned char *flags_p; - flags_p = _dbus_string_get_const_data_len (&header->data, FLAGS_OFFSET, 1); + flags_p = _dbus_string_get_const_udata_len (&header->data, FLAGS_OFFSET, 1); return (*flags_p & flag) != 0; } diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c index 9ba16e9..b58a283 100644 --- a/dbus/dbus-marshal-recursive.c +++ b/dbus/dbus-marshal-recursive.c @@ -224,7 +224,7 @@ array_reader_get_array_len (const DBusTypeReader *reader) _dbus_assert (_DBUS_ALIGN_VALUE (len_pos, 4) == (unsigned) len_pos); array_len = _dbus_unpack_uint32 (reader->byte_order, - _dbus_string_get_const_data_len (reader->value_str, len_pos, 4)); + _dbus_string_get_const_udata_len (reader->value_str, len_pos, 4)); #if RECURSIVE_MARSHAL_READ_TRACE _dbus_verbose (" reader %p len_pos %d array len %u len_offset %d\n", @@ -347,7 +347,7 @@ _dbus_type_signature_next (const char *type_str, _dbus_assert (type_str != NULL); _dbus_assert (type_pos != NULL); - start = type_str; + start = (const unsigned char *)type_str; p = start + *type_pos; _dbus_assert (*p != DBUS_STRUCT_END_CHAR); @@ -855,9 +855,9 @@ _dbus_type_reader_read_raw (const DBusTypeReader *reader, { _dbus_assert (!reader->klass->types_only); - *value_location = _dbus_string_get_const_data_len (reader->value_str, - reader->value_pos, - 0); + *value_location = _dbus_string_get_const_udata_len (reader->value_str, + reader->value_pos, + 0); } /** @@ -1934,7 +1934,7 @@ writer_recurse_array (DBusTypeWriter *writer, _dbus_assert (_DBUS_ALIGN_VALUE (sub->u.array.len_pos, 4) == (unsigned) sub->u.array.len_pos); len = _dbus_unpack_uint32 (sub->byte_order, - _dbus_string_get_const_data_len (sub->value_str, + _dbus_string_get_const_udata_len (sub->value_str, sub->u.array.len_pos, 4)); @@ -2579,7 +2579,7 @@ writer_write_reader_helper (DBusTypeWriter *writer, (unsigned) fixup.len_pos_in_reader); old_len = _dbus_unpack_uint32 (reader->byte_order, - _dbus_string_get_const_data_len (reader->value_str, + _dbus_string_get_const_udata_len (reader->value_str, fixup.len_pos_in_reader, 4)); if (old_len != fixup.new_len && !append_fixup (fixups, &fixup)) diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c index b1c1bdc..e122499 100644 --- a/dbus/dbus-marshal-validate.c +++ b/dbus/dbus-marshal-validate.c @@ -83,9 +83,9 @@ _dbus_validate_signature_with_reason (const DBusString *type_str, goto out; } - p = _dbus_string_get_const_data_len (type_str, type_pos, 0); + p = _dbus_string_get_const_udata_len (type_str, type_pos, 0); - end = _dbus_string_get_const_data_len (type_str, type_pos + len, 0); + end = _dbus_string_get_const_udata_len (type_str, type_pos + len, 0); struct_depth = 0; array_depth = 0; dict_entry_depth = 0; @@ -233,7 +233,7 @@ _dbus_validate_signature_with_reason (const DBusString *type_str, { if (*p == DBUS_TYPE_ARRAY && p != end) { - const char *p1; + const unsigned char *p1; p1 = p + 1; if (*p1 == DBUS_STRUCT_END_CHAR || *p1 == DBUS_DICT_ENTRY_END_CHAR) @@ -725,7 +725,7 @@ _dbus_validate_body_with_reason (const DBusString *expected_signature, _dbus_type_reader_init_types_only (&reader, expected_signature, expected_signature_start); - p = _dbus_string_get_const_data_len (value_str, value_pos, len); + p = _dbus_string_get_const_udata_len (value_str, value_pos, len); end = p + len; validity = validate_body_helper (&reader, byte_order, TRUE, 0, p, end, &p); @@ -800,7 +800,7 @@ _dbus_validate_path (const DBusString *str, if (len == 0) return FALSE; - s = _dbus_string_get_const_data (str) + start; + s = _dbus_string_get_const_udata (str) + start; end = s + len; if (*s != '/') @@ -941,7 +941,7 @@ _dbus_validate_interface (const DBusString *str, return FALSE; last_dot = NULL; - iface = _dbus_string_get_const_data (str) + start; + iface = _dbus_string_get_const_udata (str) + start; end = iface + len; s = iface; @@ -1015,7 +1015,7 @@ _dbus_validate_member (const DBusString *str, if (len == 0) return FALSE; - member = _dbus_string_get_const_data (str) + start; + member = _dbus_string_get_const_udata (str) + start; end = member + len; s = member; @@ -1107,7 +1107,7 @@ _dbus_validate_bus_name_full (const DBusString *str, return FALSE; last_dot = NULL; - iface = _dbus_string_get_const_data (str) + start; + iface = _dbus_string_get_const_udata (str) + start; end = iface + len; s = iface; diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h index adf709b..44ce5d2 100644 --- a/dbus/dbus-string.h +++ b/dbus/dbus-string.h @@ -362,6 +362,24 @@ dbus_bool_t _dbus_string_validate_nul (const DBusString *str, void _dbus_string_zero (DBusString *str); +static inline unsigned char * +_dbus_string_get_udata_len (DBusString *str, int start, int len) +{ + return (unsigned char *) _dbus_string_get_data_len (str, start, len); +} + +static inline const unsigned char * +_dbus_string_get_const_udata (const DBusString *str) +{ + return (const unsigned char *) _dbus_string_get_const_data (str); +} + +static inline const unsigned char * +_dbus_string_get_const_udata_len (const DBusString *str, int start, int len) +{ + return (const unsigned char *) _dbus_string_get_const_data_len (str, start, len); +} + /** * We allocate 1 byte for nul termination, plus 7 bytes for possible * align_offset, so we always need 8 bytes on top of the string's diff --git a/tools/dbus-spam.c b/tools/dbus-spam.c index c78d8ea..05d7efa 100644 --- a/tools/dbus-spam.c +++ b/tools/dbus-spam.c @@ -245,7 +245,7 @@ dbus_test_tool_spam (int argc, char **argv) n_random_sizes++; } - random_sizes = dbus_new0 (int, n_random_sizes); + random_sizes = dbus_new0 (unsigned int, n_random_sizes); if (random_sizes == NULL) tool_oom ("allocating array of message lengths"); -- 1.8.4.5