W3C home > Mailing lists > Public > html-tidy@w3.org > July to September 1999

InsertNodeAfterElement(): missing "node->next->prev = node;"

From: Advocate <wotw@inebraska.com>
Date: Sun, 1 Aug 1999 13:42:35 -0500
Message-Id: <v04205500b3ca3c3332d5@[209.50.4.88]>
To: html-tidy@w3.org
Apparently InsertNodeAfterElement is failing to create the 
"node->next->prev" link to itself when "node" is inserted after a 
node "element" which is not the last node of the "parent".  I'll 
label that node "(next)".

	element
	^ ^ |
	| | |
	| | v
	| node
	|   |
	|   |
	|   v
	(next)

The "element->next" points to "node" and "node->prev" points to 
"element", but "(next)->prev" does not point to "node" but instead it 
still points back to "element".

This was only encountered when dealing with PRE tags containing 
content illegal for PRE.  (Called twice by ParsePre to move illegal 
PRE content to be a later sibling of PRE, then open PRE again 
afterward).  The patch is below.

*** tidy26jul99/parser.c	Mon Jul 26 16:03:05 1999
--- tidy26jul99-InsertNodeAfterElement/parser.c	Thu Jul 29 12:25:56 1999
***************
*** 43,57 ****
   void InsertNodeAfterElement(Node *element, Node *node)
   {
       Node *parent;
 
       parent = element->parent;
       node->parent = parent;
 
       if (parent->last == element)
           parent->last = node;
!     else
           node->next = element->next;
 
       element->next = node;
       node->prev = element;
   }
--- 43,59 ----
   void InsertNodeAfterElement(Node *element, Node *node)
   {
       Node *parent;
 
       parent = element->parent;
       node->parent = parent;
 
       if (parent->last == element)
           parent->last = node;
!     else {
           node->next = element->next;
+         node->next->prev = node;
+     }
 
       element->next = node;
       node->prev = element;
   }
-- 
          ,=<#)-=#  <http://www.war-of-the-worlds.org/>
     ,_--//--_,
  _-~_-(####)-_~-_  "Did you see that Parkins boy's body in the tunnels?" "Just
(#>_--'~--~`--_<#)  the photos.  Worst thing I've ever seen; kid had no face."
Received on Sunday, 1 August 1999 14:48:06 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 3 April 2012 06:13:42 GMT