gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re[2]: [gnugo-devel] sgf/sgfnode.c possible error


From: Paul Pogonyshev
Subject: Re: Re[2]: [gnugo-devel] sgf/sgfnode.c possible error
Date: Thu, 16 Sep 2004 01:59:29 -0200
User-agent: KMail/1.4.3

I wrote:

> Actually, it would make sense to assert for `node->parent's
> being non-NULL, but since we are going to release 3.6 soon
> and I'm not sure that this assertion will not fail (the
> code is quite messy), I'm leaving this out.

It's becoming a bad habbit of finding corrections 30 seconds
after sending mail.

Grepping shows that these functions are used only from
sgfAddPlay() with `node->child' as argument, which guarantees
a non-NULL parent.  So, adding assertions must be absolutely
safe.

Paul



--- sgfnode.c   12 Feb 2004 19:34:20 -0200      1.27
+++ sgfnode.c   16 Sep 2004 01:59:08 -0200      
@@ -706,11 +706,12 @@ SGFNode *
 sgfStartVariant(SGFNode *node)
 {
   assert(node);
+  assert(node->parent);
 
   while (node->next)
     node = node->next;
   node->next = sgfNewNode();
-  node->next->parent = node;
+  node->next->parent = node->parent;
 
   return node->next;
 }
@@ -726,12 +727,13 @@ sgfStartVariantFirst(SGFNode *node)
   SGFNode *old_first_child = node;
   SGFNode *new_first_child = sgfNewNode();
 
+  assert(node);
+  assert(node->parent);
+
   new_first_child->next = old_first_child;
-  if (old_first_child->parent)
-    new_first_child->parent = old_first_child->parent;
-  old_first_child->parent = new_first_child;
-  if (new_first_child->parent)
-    new_first_child->parent->child = new_first_child;
+  new_first_child->parent = old_first_child->parent;
+
+  new_first_child->parent->child = new_first_child;
 
   return new_first_child;
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]