fix a typo in previous commit
[lcore.git] / blinklist.pas
index 2079b751bf12128c3cfd1b1663d5216c5ad67405..5c3391d890a9a82ad4966e3c56d5e2bc6d4b9380 100755 (executable)
@@ -1,21 +1,9 @@
-(*\r
- *  beware IRC services, blinklist.pas\r
- *  Copyright (C) 2002 Bas Steendijk\r
- *\r
- *  This program is free software; you can redistribute it and/or modify\r
- *  it under the terms of the GNU General Public License as published by\r
- *  the Free Software Foundation; either version 2 of the License, or\r
- *  (at your option) any later version.\r
- *\r
- *  This program is distributed in the hope that it will be useful,\r
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- *  GNU General Public License for more details.\r
- *\r
- *  You should have received a copy of the GNU General Public License\r
- *  along with this program; if not, write to the Free Software\r
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- *)\r
+\r
+{ Copyright (C) 2005 Bas Steendijk\r
+  For conditions of distribution and use, see copyright notice in zlib_license.txt\r
+    which is included in the package\r
+      ----------------------------------------------------------------------------- }\r
+\r
 unit blinklist;\r
 {$ifdef fpc}\r
   {$mode delphi}\r
@@ -66,11 +54,14 @@ var
   linklistdebug:integer;\r
 \r
 implementation\r
+
+uses sysutils;
 \r
 procedure linklistadd(var baseptr:tlinklist;newptr:tlinklist);\r
 var\r
   p:tlinklist;\r
 begin\r
+  if (newptr=baseptr) or assigned(newptr.prev) then raise exception.create('linklist double insertion detected');
   p := baseptr;\r
   baseptr := newptr;\r
   baseptr.prev := nil;\r
@@ -82,13 +73,16 @@ procedure linklistdel(var baseptr:tlinklist;item:tlinklist);
 begin\r
   if item = baseptr then baseptr := item.next;\r
   if item.prev <> nil then item.prev.next := item.next;\r
-  if item.next <> nil then item.next.prev := item.prev;\r
+  if item.next <> nil then item.next.prev := item.prev;
+  item.prev := nil;
+  item.next := nil;\r
 end;\r
 \r
 procedure linklist2add(var baseptr,newptr:tlinklist2);\r
 var\r
   p:tlinklist2;\r
 begin\r
+  if (newptr=baseptr) or assigned(newptr.prev2) then raise exception.create('linklist2 double insertion detected');
   p := baseptr;\r
   baseptr := newptr;\r
   baseptr.prev2 := nil;\r
@@ -100,7 +94,9 @@ procedure linklist2del(var baseptr:tlinklist2;item:tlinklist2);
 begin\r
   if item = baseptr then baseptr := item.next2;\r
   if item.prev2 <> nil then item.prev2.next2 := item.next2;\r
-  if item.next2 <> nil then item.next2.prev2 := item.prev2;\r
+  if item.next2 <> nil then item.next2.prev2 := item.prev2;
+  item.prev2 := nil;
+  item.next2 := nil;\r
 end;\r
 \r
 constructor tlinklist.create;\r