summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-string.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2007-06-10 04:54:45 +0000
committerHavoc Pennington <hp@redhat.com>2007-06-10 04:54:45 +0000
commita789b7b38cb4f4540a41444cbd64bf7ada2d60d2 (patch)
treedb5164def7f5d19266bc4ebfb4ce740f269d79e2 /dbus/dbus-string.c
parent7be5fd95cdccdca28937804f32ca8b1308887d09 (diff)
2007-06-09 Havoc Pennington <hp@redhat.com>
* dbus/dbus-string.c (_dbus_string_pop_line): fix this not to think an empty line is the end of the file. Also, fix some whitespace. * dbus/dbus-string-util.c: add more tests for _dbus_string_pop_line() revealing that it thinks an empty line is the end of the file, which broke dbus-auth-script.c so it didn't really run the scripts * dbus/dbus-auth.c: add ANONYMOUS mechanism * dbus/dbus-auth-script.c (_dbus_auth_script_run): fix to detect an empty/no-op auth script; add commands to check that we have or don't have the expected credentials
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r--dbus/dbus-string.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index d83a3f39..6177a751 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -1804,9 +1804,9 @@ _dbus_string_find (const DBusString *str,
*/
dbus_bool_t
_dbus_string_find_eol (const DBusString *str,
- int start,
- int *found,
- int *found_len)
+ int start,
+ int *found,
+ int *found_len)
{
int i;
@@ -1843,7 +1843,7 @@ _dbus_string_find_eol (const DBusString *str,
if (found_len)
*found_len = 1;
return TRUE;
- }
+ }
++i;
}
@@ -2093,17 +2093,33 @@ _dbus_string_pop_line (DBusString *source,
_dbus_string_set_length (dest, 0);
eol = 0;
+ eol_len = 0;
if (!_dbus_string_find_eol (source, 0, &eol, &eol_len))
- eol = _dbus_string_get_length (source);
+ {
+ _dbus_assert (eol == _dbus_string_get_length (source));
+ if (eol == 0)
+ {
+ /* If there's no newline and source has zero length, we're done */
+ return FALSE;
+ }
+ /* otherwise, the last line of the file has no eol characters */
+ }
- if (eol == 0)
- return FALSE; /* eof */
+ /* remember eol can be 0 if it's an empty line, but eol_len should not be zero also
+ * since find_eol returned TRUE
+ */
if (!_dbus_string_move_len (source, 0, eol + eol_len, dest, 0))
- return FALSE;
-
+ return FALSE;
+
/* remove line ending */
- return _dbus_string_set_length(dest, eol);
+ if (!_dbus_string_set_length (dest, eol))
+ {
+ _dbus_assert_not_reached ("out of memory when shortening a string");
+ return FALSE;
+ }
+
+ return TRUE;
}
#ifdef DBUS_BUILD_TESTS