From 45c0e717d9d354a20db5d705036cb570bfa78cee Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 3 Jul 2017 17:31:37 +0100 Subject: [PATCH 01/12] DBusString: Reverse the sense of ->invalid It's easier to implement a stack-allocated string that is valid to free (but for no other purpose) if we consider all-bits-zero to be invalid. Signed-off-by: Simon McVittie --- dbus/dbus-string-private.h | 4 ++-- dbus/dbus-string-util.c | 2 +- dbus/dbus-string.c | 6 +++--- dbus/dbus-string.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dbus/dbus-string-private.h b/dbus/dbus-string-private.h index 2e6de900..10f87bbc 100644 --- a/dbus/dbus-string-private.h +++ b/dbus/dbus-string-private.h @@ -47,7 +47,7 @@ typedef struct int allocated; /**< Allocated size of data */ unsigned int constant : 1; /**< String data is not owned by DBusString */ unsigned int locked : 1; /**< DBusString has been locked and can't be changed */ - unsigned int invalid : 1; /**< DBusString is invalid (e.g. already freed) */ + unsigned int valid : 1; /**< DBusString is valid (initialized and not freed) */ unsigned int align_offset : 3; /**< str - align_offset is the actual malloc block */ } DBusRealString; @@ -77,7 +77,7 @@ _DBUS_STATIC_ASSERT (sizeof (DBusRealString) == sizeof (DBusString)); do { \ (void) real; /* might be unused unless asserting */ \ _dbus_assert ((real) != NULL); \ - _dbus_assert (!(real)->invalid); \ + _dbus_assert ((real)->valid); \ _dbus_assert ((real)->len >= 0); \ _dbus_assert ((real)->allocated >= 0); \ _dbus_assert ((real)->len <= ((real)->allocated - _DBUS_STRING_ALLOCATION_PADDING)); \ diff --git a/dbus/dbus-string-util.c b/dbus/dbus-string-util.c index 750275a0..08e0e917 100644 --- a/dbus/dbus-string-util.c +++ b/dbus/dbus-string-util.c @@ -242,7 +242,7 @@ _dbus_string_test (void) _dbus_assert (real_test_static_string->allocated > 5); _dbus_assert (real_test_static_string->constant); _dbus_assert (real_test_static_string->locked); - _dbus_assert (!real_test_static_string->invalid); + _dbus_assert (real_test_static_string->valid); _dbus_assert (real_test_static_string->align_offset == 0); /* Test shortening and setting length */ diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index 98d9f2b7..75134d6a 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -156,7 +156,7 @@ _dbus_string_init_preallocated (DBusString *str, real->constant = FALSE; real->locked = FALSE; - real->invalid = FALSE; + real->valid = TRUE; real->align_offset = 0; fixup_alignment (real); @@ -225,7 +225,7 @@ _dbus_string_init_const_len (DBusString *str, real->allocated = real->len + _DBUS_STRING_ALLOCATION_PADDING; /* a lie, just to avoid special-case assertions... */ real->constant = TRUE; real->locked = TRUE; - real->invalid = FALSE; + real->valid = TRUE; real->align_offset = 0; /* We don't require const strings to be 8-byte aligned as the @@ -273,7 +273,7 @@ _dbus_string_free (DBusString *str) dbus_free (real->str - real->align_offset); - real->invalid = TRUE; + real->valid = FALSE; } static dbus_bool_t diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h index 2f78a04c..e7060b9f 100644 --- a/dbus/dbus-string.h +++ b/dbus/dbus-string.h @@ -405,7 +405,7 @@ _dbus_string_get_const_udata_len (const DBusString *str, int start, int len) sizeof(_dbus_static_string_##name) - 1, \ sizeof(_dbus_static_string_##name) + \ _DBUS_STRING_ALLOCATION_PADDING, \ - TRUE, TRUE, FALSE, 0 } + TRUE, TRUE, TRUE, 0 } DBUS_END_DECLS -- 2.15.0