]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
DBusString: Reverse the sense of ->invalid
authorSimon McVittie <smcv@collabora.com>
Mon, 3 Jul 2017 16:31:37 +0000 (17:31 +0100)
committerSimon McVittie <smcv@collabora.com>
Fri, 24 Nov 2017 12:16:56 +0000 (12:16 +0000)
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 <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104

dbus/dbus-string-private.h
dbus/dbus-string-util.c
dbus/dbus-string.c
dbus/dbus-string.h

index 2e6de900fdc95e7278abe18b163cb13079cd26d9..10f87bbc613e1fd72fccd14799a0f4b7bc052199 100644 (file)
@@ -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)); \
index 750275a0f6bfeff2d0bb40bdf3536b214f2f8d4e..08e0e917a267822602d51710e7d72837791a979d 100644 (file)
@@ -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 */
index 98d9f2b7216e0e64fd738e942d6ecb2588b295ef..75134d6a8b57efffc603a3bf2f1f0c93394fd5d0 100644 (file)
@@ -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
index 2f78a04c0766d65f5ceff61f6de70c8005e60c0f..e7060b9fb62db2585040fa55be3644227f9e39b6 100644 (file)
@@ -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