From cdeee71e115f416bd82677e231ae01bf6d938e6b Mon Sep 17 00:00:00 2001 From: Peter McCurdy Date: Mon, 1 Sep 2008 00:29:25 -0400 Subject: [PATCH] Replace unsigned char*s with signed char*s in dbus/dbus-marshal-* A lot of the warnings in DBus are due to mismatched signed vs unsigned char*s. So far, this clears all such warnings out of dbus/dbus-marshal-*, except for dbus-marshal-validate.c The only code behaviour change is a simplification of how byte sequences are printed to the console; it now lets printf do the zero-padding work. Note that the %x modifier implicitly converts to unsigned, so the output remains the same. --- dbus/dbus-internals.h | 12 +++--- dbus/dbus-marshal-basic.c | 74 +++++++++++++++++------------------- dbus/dbus-marshal-basic.h | 20 +++++----- dbus/dbus-marshal-byteswap.c | 6 +- dbus/dbus-marshal-header.c | 4 +- dbus/dbus-marshal-recursive-util.c | 4 +- dbus/dbus-marshal-recursive.c | 6 +- dbus/dbus-marshal-recursive.h | 2 +- 8 files changed, 62 insertions(+), 66 deletions(-) diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 3e5f989..38692fb 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -236,12 +236,12 @@ typedef void (* DBusForeachFunction) (void *element, dbus_bool_t _dbus_set_fd_nonblocking (int fd, DBusError *error); -void _dbus_verbose_bytes (const unsigned char *data, - int len, - int offset); -void _dbus_verbose_bytes_of_string (const DBusString *str, - int start, - int len); +void _dbus_verbose_bytes (const char *data, + int len, + int offset); +void _dbus_verbose_bytes_of_string (const DBusString *str, + int start, + int len); const char* _dbus_header_field_to_string (int header_field); diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c index 365cf04..8e85112 100644 --- a/dbus/dbus-marshal-basic.c +++ b/dbus/dbus-marshal-basic.c @@ -46,7 +46,7 @@ static void pack_2_octets (dbus_uint16_t value, int byte_order, - unsigned char *data) + char *data) { _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 2) == data); @@ -59,7 +59,7 @@ pack_2_octets (dbus_uint16_t value, static void pack_4_octets (dbus_uint32_t value, int byte_order, - unsigned char *data) + char *data) { _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data); @@ -70,9 +70,9 @@ pack_4_octets (dbus_uint32_t value, } static void -pack_8_octets (DBusBasicValue value, - int byte_order, - unsigned char *data) +pack_8_octets (DBusBasicValue value, + int byte_order, + char *data) { _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 8) == data); @@ -97,7 +97,7 @@ pack_8_octets (DBusBasicValue value, void _dbus_pack_uint32 (dbus_uint32_t value, int byte_order, - unsigned char *data) + char *data) { pack_4_octets (value, byte_order, data); } @@ -170,8 +170,8 @@ unpack_8_octets (int byte_order, * @returns the integer */ dbus_uint16_t -_dbus_unpack_uint16 (int byte_order, - const unsigned char *data) +_dbus_unpack_uint16 (int byte_order, + const char *data) { _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 2) == data); @@ -191,8 +191,8 @@ _dbus_unpack_uint16 (int byte_order, * @returns the integer */ dbus_uint32_t -_dbus_unpack_uint32 (int byte_order, - const unsigned char *data) +_dbus_unpack_uint32 (int byte_order, + const char *data) { _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data); @@ -679,13 +679,13 @@ enum }; static dbus_bool_t -marshal_len_followed_by_bytes (int marshal_as, - DBusString *str, - int insert_at, - const unsigned char *value, - int data_len, /* doesn't include nul if any */ - int byte_order, - int *pos_after) +marshal_len_followed_by_bytes (int marshal_as, + DBusString *str, + int insert_at, + const char *value, + int data_len, /* doesn't include nul if any */ + int byte_order, + int *pos_after) { int pos; DBusString value_str; @@ -849,12 +849,12 @@ _dbus_marshal_write_basic (DBusString *str, } static dbus_bool_t -marshal_1_octets_array (DBusString *str, - int insert_at, - const unsigned char *value, - int n_elements, - int byte_order, - int *pos_after) +marshal_1_octets_array (DBusString *str, + int insert_at, + const char *value, + int n_elements, + int byte_order, + int *pos_after) { int pos; DBusString value_str; @@ -883,18 +883,15 @@ marshal_1_octets_array (DBusString *str, * @param alignment size of each element */ void -_dbus_swap_array (unsigned char *data, - int n_elements, - int alignment) +_dbus_swap_array (char *data, + int n_elements, + int alignment) { - unsigned char *d; - unsigned char *end; + char *d; + char *end; _dbus_assert (_DBUS_ALIGN_ADDRESS (data, alignment) == data); - /* we use const_data and cast it off so DBusString can be a const string - * for the unit tests. don't ask. - */ d = data; end = d + (n_elements * alignment); @@ -944,7 +941,7 @@ swap_array (DBusString *str, /* we use const_data and cast it off so DBusString can be a const string * for the unit tests. don't ask. */ - _dbus_swap_array ((unsigned char*) (_dbus_string_get_const_data (str) + array_start), + _dbus_swap_array ((char*)(_dbus_string_get_const_data (str) + array_start), n_elements, alignment); } } @@ -980,7 +977,7 @@ marshal_fixed_multi (DBusString *str, goto error; _dbus_string_init_const_len (&t, - (const unsigned char*) value, + (const char*) value, len_in_bytes); if (!_dbus_string_copy (&t, 0, @@ -1313,12 +1310,12 @@ _dbus_type_to_string (int typecode) * @param offset where to start counting for byte indexes */ void -_dbus_verbose_bytes (const unsigned char *data, - int len, - int offset) +_dbus_verbose_bytes (const char *data, + int len, + int offset) { int i; - const unsigned char *aligned; + const char *aligned; _dbus_assert (len >= 0); @@ -1355,8 +1352,7 @@ _dbus_verbose_bytes (const unsigned char *data, data[i] <= 126) _dbus_verbose (" '%c' ", data[i]); else - _dbus_verbose ("0x%s%x ", - data[i] <= 0xf ? "0" : "", data[i]); + _dbus_verbose ("0x%02x ", data[i]); ++i; diff --git a/dbus/dbus-marshal-basic.h b/dbus/dbus-marshal-basic.h index 28c751f..6de0d60 100644 --- a/dbus/dbus-marshal-basic.h +++ b/dbus/dbus-marshal-basic.h @@ -181,16 +181,16 @@ typedef union #endif #ifndef _dbus_unpack_uint16 -dbus_uint16_t _dbus_unpack_uint16 (int byte_order, - const unsigned char *data); +dbus_uint16_t _dbus_unpack_uint16 (int byte_order, + const char *data); #endif -void _dbus_pack_uint32 (dbus_uint32_t value, - int byte_order, - unsigned char *data); +void _dbus_pack_uint32 (dbus_uint32_t value, + int byte_order, + char *data); #ifndef _dbus_unpack_uint32 -dbus_uint32_t _dbus_unpack_uint32 (int byte_order, - const unsigned char *data); +dbus_uint32_t _dbus_unpack_uint32 (int byte_order, + const char *data); #endif dbus_bool_t _dbus_marshal_set_basic (DBusString *str, @@ -254,8 +254,8 @@ int _dbus_first_type_in_signature (const DBusString *str, int _dbus_first_type_in_signature_c_str (const char *str, int pos); -void _dbus_swap_array (unsigned char *data, - int n_elements, - int alignment); +void _dbus_swap_array (char *data, + int n_elements, + int alignment); #endif /* DBUS_MARSHAL_BASIC_H */ diff --git a/dbus/dbus-marshal-byteswap.c b/dbus/dbus-marshal-byteswap.c index 6c9fff5..ab34553 100644 --- a/dbus/dbus-marshal-byteswap.c +++ b/dbus/dbus-marshal-byteswap.c @@ -35,8 +35,8 @@ byteswap_body_helper (DBusTypeReader *reader, dbus_bool_t walk_reader_to_end, int old_byte_order, int new_byte_order, - unsigned char *p, - unsigned char **new_p) + char *p, + char **new_p) { int current_type; @@ -115,7 +115,7 @@ byteswap_body_helper (DBusTypeReader *reader, else { DBusTypeReader sub; - const unsigned char *array_end; + const char *array_end; array_end = p + array_len; diff --git a/dbus/dbus-marshal-header.c b/dbus/dbus-marshal-header.c index 8aba6a9..69d9e51 100644 --- a/dbus/dbus-marshal-header.c +++ b/dbus/dbus-marshal-header.c @@ -1424,7 +1424,7 @@ _dbus_header_toggle_flag (DBusHeader *header, dbus_uint32_t flag, dbus_bool_t value) { - unsigned char *flags_p; + char *flags_p; flags_p = _dbus_string_get_data_len (&header->data, FLAGS_OFFSET, 1); @@ -1445,7 +1445,7 @@ dbus_bool_t _dbus_header_get_flag (DBusHeader *header, dbus_uint32_t flag) { - const unsigned char *flags_p; + const char *flags_p; flags_p = _dbus_string_get_const_data_len (&header->data, FLAGS_OFFSET, 1); diff --git a/dbus/dbus-marshal-recursive-util.c b/dbus/dbus-marshal-recursive-util.c index c8ae93d..787191c 100644 --- a/dbus/dbus-marshal-recursive-util.c +++ b/dbus/dbus-marshal-recursive-util.c @@ -2179,7 +2179,7 @@ int16_read_multi (TestTypeNode *node, for (i = 0; i < count; i++) _dbus_assert (((dbus_int16_t)_dbus_unpack_uint16 (reader->byte_order, - (const unsigned char*)values + (i * 2))) == + (const char*)values + (i * 2))) == int16_from_seed (seed + i)); return TRUE; @@ -2316,7 +2316,7 @@ int32_read_multi (TestTypeNode *node, for (i = 0; i < count; i++) _dbus_assert (((int)_dbus_unpack_uint32 (reader->byte_order, - (const unsigned char*)values + (i * 4))) == + (const char*)values + (i * 4))) == int32_from_seed (seed + i)); return TRUE; diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c index 76ee344..5486650 100644 --- a/dbus/dbus-marshal-recursive.c +++ b/dbus/dbus-marshal-recursive.c @@ -327,8 +327,8 @@ void _dbus_type_signature_next (const char *type_str, int *type_pos) { - const unsigned char *p; - const unsigned char *start; + const char *p; + const char *start; _dbus_assert (type_str != NULL); _dbus_assert (type_pos != NULL); @@ -837,7 +837,7 @@ _dbus_type_reader_get_value_pos (const DBusTypeReader *reader) */ void _dbus_type_reader_read_raw (const DBusTypeReader *reader, - const unsigned char **value_location) + const char **value_location) { _dbus_assert (!reader->klass->types_only); diff --git a/dbus/dbus-marshal-recursive.h b/dbus/dbus-marshal-recursive.h index 14f38b2..6ec8af0 100644 --- a/dbus/dbus-marshal-recursive.h +++ b/dbus/dbus-marshal-recursive.h @@ -120,7 +120,7 @@ void _dbus_type_reader_read_fixed_multi (const DBusTypeReader * void *value, int *n_elements); void _dbus_type_reader_read_raw (const DBusTypeReader *reader, - const unsigned char **value_location); + const char **value_location); void _dbus_type_reader_recurse (DBusTypeReader *reader, DBusTypeReader *subreader); dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader); -- 1.5.4.3