branch: externals/m-buffer
commit a3078a58edb50661c05c334d7a8c47b1b1188b70
Author: Phillip Lord <[email protected]>
Commit: Phillip Lord <[email protected]>
exact-subtract no longer crashes on last non-match
Previously exact-subtract would crash if the last element in n
did not also occur in m. We now check for exhaustion of n explicitly and
so avoid doing a numerical check between marker and nil.
---
m-buffer.el | 7 +++++++
test/m-buffer-test.el | 16 ++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/m-buffer.el b/m-buffer.el
index a505c40156..96d8525c7c 100644
--- a/m-buffer.el
+++ b/m-buffer.el
@@ -374,10 +374,17 @@ runs faster but has some restrictions."
Both M and N must be fully ordered, and any element in N must be
in M."
(if n
+ ;; n-eaten contains the remaining elements of n that we haven't tested
+ ;; for yet. We throw them away as we go
(let ((n-eaten n))
(-remove
(lambda (o)
(cond
+ ;; n-eaten has been eaten. Check here or later "<" comparison
crashes.
+ ((not n-eaten)
+ ;; return nil because we always want things in m now.
+ nil
+ )
;; we have a match so throw away the first element of n-eaten
;; which we won't need again.
((m-buffer-match-equal
diff --git a/test/m-buffer-test.el b/test/m-buffer-test.el
index 3253ce2505..2e750c59ad 100644
--- a/test/m-buffer-test.el
+++ b/test/m-buffer-test.el
@@ -356,6 +356,22 @@
'((1 1))
nil))))
+(ert-deftest exact-subtract-error-simplified ()
+ (should
+ (equal
+ '((2 2))
+ (m-buffer-match-exact-subtract
+ '((1 1) (2 2))
+ '((1 1))))))
+(ert-deftest exact-subtract-error ()
+ "This is a test case for a bug found from linked-buffer."
+ (should
+ (equal
+ '((19 31 19 19))
+ (m-buffer-match-exact-subtract
+ '((1 18 1 1)
+ (19 31 19 19))
+ '((1 18))))))
;;; m-buffer-test.el ends here