aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/llist.c7
-rwxr-xr-xscripts/test/test.test4
-rw-r--r--toys/posix/patch.c10
3 files changed, 11 insertions, 10 deletions
diff --git a/lib/llist.c b/lib/llist.c
index 596da40f..71a187db 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -37,8 +37,11 @@ void *dlist_pop(void *list)
{
struct double_list **pdlist = (struct double_list **)list, *dlist = *pdlist;
- dlist->next->prev = dlist->prev;
- dlist->prev->next = *pdlist = dlist->next;
+ if (dlist->next == dlist) *pdlist = 0;
+ else {
+ dlist->next->prev = dlist->prev;
+ dlist->prev->next = *pdlist = dlist->next;
+ }
return dlist;
}
diff --git a/scripts/test/test.test b/scripts/test/test.test
index a66dd3c6..f5011573 100755
--- a/scripts/test/test.test
+++ b/scripts/test/test.test
@@ -61,3 +61,7 @@ testing "test -gt" "arith_test -gt" "g\n" "" ""
testing "test -ge" "arith_test -ge" "e\ng\n" "" ""
testing "test -lt" "arith_test -lt" "l\n" "" ""
testing "test -le" "arith_test -le" "l\ne\n" "" ""
+
+# test ! = -o a
+# test ! \( = -o a \)
+# test \( ! = \) -o a
diff --git a/toys/posix/patch.c b/toys/posix/patch.c
index bb443484..7fb6add3 100644
--- a/toys/posix/patch.c
+++ b/toys/posix/patch.c
@@ -204,18 +204,12 @@ static int apply_one_hunk(void)
if (PATCH_DEBUG) fprintf(stderr, "NOT: %s\n", plist->data);
TT.state = 3;
- check = llist_pop(&buf);
- check->prev->next = buf;
- buf->prev = check->prev;
- do_line(check);
+ do_line(check = dlist_pop(&buf));
plist = TT.current_hunk;
// If we've reached the end of the buffer without confirming a
// match, read more lines.
- if (check==buf) {
- buf = 0;
- break;
- }
+ if (!buf) break;
check = buf;
} else {
if (PATCH_DEBUG) fprintf(stderr, "MAYBE: %s\n", plist->data);