summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorrockcavera <rockcavera@gmail.com>2021-12-30 17:52:48 -0300
committerGitHub <noreply@github.com>2021-12-30 21:52:48 +0100
commitdc5c88ca79e871aefa76c7fefae4282c639a3283 (patch)
tree5d7acf77abf325b2592c899205512cb544addb78 /lib
parent23d64be860958fb7149baed44f6e493394950d69 (diff)
downloadNim-dc5c88ca79e871aefa76c7fefae4282c639a3283.tar.gz
Fix #19297 - fixing broken list after adding empty list (#19299)
* Update lists.nim

* Update tlists.nim

* removed check `if b.tail != nil`

The tail of the list being null it is still possible to retrieve its end by going through all nodes from the head. So checking for null from `b.tail` is unnecessary. However, setting `a.tail = b.tail` only if `a.head != nil`, so you don't break a good list with an already broken one.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/collections/lists.nim11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/pure/collections/lists.nim b/lib/pure/collections/lists.nim
index 8b255fb60..de5550d6e 100644
--- a/lib/pure/collections/lists.nim
+++ b/lib/pure/collections/lists.nim
@@ -530,11 +530,12 @@ proc addMoved*[T](a, b: var SinglyLinkedList[T]) {.since: (1, 5, 1).} =
         ci
     assert s == [0, 1, 0, 1, 0, 1]
 
-  if a.tail != nil:
-    a.tail.next = b.head
-  a.tail = b.tail
-  if a.head == nil:
-    a.head = b.head
+  if b.head != nil:
+    if a.head == nil:
+      a.head = b.head
+    else:
+      a.tail.next = b.head
+    a.tail = b.tail
   if a.addr != b.addr:
     b.head = nil
     b.tail = nil