+randomly_set_extreme_ints (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int i;
+ int byte_order;
+ const char *d;
+ dbus_uint32_t orig;
+ static int which = 0;
+ unsigned int extreme_ints[] = {
+ _DBUS_INT_MAX,
+ _DBUS_UINT_MAX,
+ _DBUS_INT_MAX - 1,
+ _DBUS_UINT_MAX - 1,
+ _DBUS_INT_MAX - 2,
+ _DBUS_UINT_MAX - 2,
+ _DBUS_INT_MAX - 17,
+ _DBUS_UINT_MAX - 17,
+ _DBUS_INT_MAX / 2,
+ _DBUS_INT_MAX / 3,
+ _DBUS_UINT_MAX / 2,
+ _DBUS_UINT_MAX / 3,
+ 0, 1, 2, 3,
+ (unsigned int) -1,
+ (unsigned int) -2,
+ (unsigned int) -3
+ };
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ if (_dbus_string_get_length (mutated) < 12)
+ return;
+
+ d = _dbus_string_get_const_data (mutated);
+
+ if (!(*d == DBUS_LITTLE_ENDIAN ||
+ *d == DBUS_BIG_ENDIAN))
+ return;
+
+ byte_order = *d;
+
+ i = random_int_in_range (4, _dbus_string_get_length (mutated) - 8);
+ i = _DBUS_ALIGN_VALUE (i, 4);
+
+ orig = _dbus_demarshal_uint32 (mutated, byte_order, i, NULL);
+
+ which = random_int_in_range (0, _DBUS_N_ELEMENTS (extreme_ints));
+
+ _dbus_assert (which >= 0);
+ _dbus_assert (which < _DBUS_N_ELEMENTS (extreme_ints));
+
+ _dbus_marshal_set_uint32 (mutated, byte_order, i,
+ extreme_ints[which]);
+}
+
+static int
+random_type (void)
+{
+ const char types[] = {
+ DBUS_TYPE_INVALID,
+ DBUS_TYPE_NIL,
+ DBUS_TYPE_BYTE,
+ DBUS_TYPE_BOOLEAN,
+ DBUS_TYPE_INT32,
+ DBUS_TYPE_UINT32,
+ DBUS_TYPE_INT64,
+ DBUS_TYPE_UINT64,
+ DBUS_TYPE_DOUBLE,
+ DBUS_TYPE_STRING,
+ DBUS_TYPE_CUSTOM,
+ DBUS_TYPE_ARRAY,
+ DBUS_TYPE_DICT,
+ DBUS_TYPE_OBJECT_PATH
+ };
+
+ _dbus_assert (_DBUS_N_ELEMENTS (types) == DBUS_NUMBER_OF_TYPES + 1);
+
+ return types[ random_int_in_range (0, _DBUS_N_ELEMENTS (types)) ];
+}
+
+static void
+randomly_change_one_type (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int i;
+ int len;
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ if (_dbus_string_get_length (mutated) == 0)
+ return;
+
+ len = _dbus_string_get_length (mutated);
+ i = random_int_in_range (0, len);
+
+ /* Look for a type starting at a random location,
+ * and replace with a different type
+ */
+ while (i < len)
+ {
+ int b;
+ b = _dbus_string_get_byte (mutated, i);
+ if (dbus_type_is_valid (b))
+ {
+ _dbus_string_set_byte (mutated, i, random_type ());
+ return;
+ }
+ ++i;
+ }
+}
+
+static int times_we_did_each_thing[7] = { 0, };
+
+static void