From 6c9f6cb86a54d797e03910357d372be18e9adf1f Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 6 Jun 2011 16:36:13 +0100 Subject: [PATCH 5/9] assert that DBusTypeWriter is valid on entry to its extern methods The only exceptions are _dbus_type_writer_clear() and the _dbus_type_writer_init() family. --- dbus/dbus-marshal-recursive.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c index 5ce5e8e..3e0c634 100644 --- a/dbus/dbus-marshal-recursive.c +++ b/dbus/dbus-marshal-recursive.c @@ -2059,6 +2059,8 @@ _dbus_type_writer_recurse (DBusTypeWriter *writer, { int contained_type_len; + _DBUS_ASSERT_TYPE_WRITER (writer); + if (contained_type) contained_type_len = find_len_of_complete_type (contained_type, contained_type_start); else @@ -2092,6 +2094,8 @@ _dbus_type_writer_append_array (DBusTypeWriter *writer, { int contained_type_len; + _DBUS_ASSERT_TYPE_WRITER (writer); + if (contained_type) contained_type_len = find_len_of_complete_type (contained_type, contained_type_start); else @@ -2124,6 +2128,9 @@ dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer, DBusTypeWriter *sub) { + _DBUS_ASSERT_TYPE_WRITER (writer); + _DBUS_ASSERT_TYPE_WRITER (sub); + /* type_pos_is_expectation never gets unset once set, or we'd get all hosed */ _dbus_assert (!writer->type_pos_is_expectation || (writer->type_pos_is_expectation && sub->type_pos_is_expectation)); @@ -2259,6 +2266,8 @@ _dbus_type_writer_write_basic (DBusTypeWriter *writer, { dbus_bool_t retval; + _DBUS_ASSERT_TYPE_WRITER (writer); + /* First ensure that our type realloc will succeed */ if (!writer->type_pos_is_expectation && writer->type_str != NULL) { @@ -2306,6 +2315,8 @@ _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer, const void *value, int n_elements) { + _DBUS_ASSERT_TYPE_WRITER (writer); + _dbus_assert (writer->container_type == DBUS_TYPE_ARRAY); _dbus_assert (dbus_type_is_fixed (element_type)); _dbus_assert (writer->type_pos_is_expectation); @@ -2632,6 +2643,8 @@ _dbus_type_writer_write_reader_partial (DBusTypeWriter *writer, int new_bytes; int orig_enabled; + _DBUS_ASSERT_TYPE_WRITER (writer); + orig = *writer; orig_type_len = _dbus_string_get_length (writer->type_str); orig_value_len = _dbus_string_get_length (writer->value_str); @@ -2676,6 +2689,8 @@ dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer, DBusTypeReader *reader) { + _DBUS_ASSERT_TYPE_WRITER (writer); + return _dbus_type_writer_write_reader_partial (writer, reader, NULL, 0, 0, NULL); } @@ -2692,6 +2707,8 @@ static void _dbus_type_writer_set_enabled (DBusTypeWriter *writer, dbus_bool_t enabled) { + _DBUS_ASSERT_TYPE_WRITER (writer); + writer->enabled = enabled != FALSE; } -- 1.7.6.3