- next = tail->next;
-
- if (marker == tail)
- {
- if (!prev)
- {
- BUF_MARKERS (b) = next;
- /* Deleting first marker from the buffer's chain. Crash
- if new first marker in chain does not say it belongs
- to the same buffer, or at least that they have the same
- base buffer. */
- if (next && b->text != next->buffer->text)
- abort ();
- }
- else
- prev->next = next;
- /* We have removed the marker from the chain;
- no need to scan the rest of the chain. */
- return;
- }
- else
- prev = tail;
- tail = next;
+ register struct Lisp_Marker *tail, **prev;
+
+ /* No dead buffers here. */
+ eassert (BUFFER_LIVE_P (b));
+
+ marker->buffer = NULL;
+ prev = &BUF_MARKERS (b);
+
+ for (tail = BUF_MARKERS (b); tail; prev = &tail->next, tail = *prev)
+ if (marker == tail)
+ {
+ if (*prev == BUF_MARKERS (b))
+ {
+ /* Deleting first marker from the buffer's chain. Crash
+ if new first marker in chain does not say it belongs
+ to the same buffer, or at least that they have the same
+ base buffer. */
+ if (tail->next && b->text != tail->next->buffer->text)
+ emacs_abort ();
+ }
+ *prev = tail->next;
+ /* We have removed the marker from the chain;
+ no need to scan the rest of the chain. */
+ break;
+ }
+
+ /* Error if marker was not in it's chain. */
+ eassert (tail != NULL);