Bug in ASTFactory::addASTChild (C++ support library)
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, June 4, 2004 10:02 AM

Hello, I'm spanish so my English perhaps is not very good. But I would like to advice you about a bug I have found on ASTFactory::addASTChild method of the C++ support library. Here is the implementation of the method: if (child) { if (!currentAST.root) { // Make new child the current root currentAST.root = child; } else { if (!currentAST.child) { // Add new child to current root currentAST.root->setFirstChild(child); } else { currentAST.child->setNextSibling(child); } } // Make new child the current child cu   More>>

Hello, I'm spanish so my English perhaps is not very good.



But I would like to advice you about a bug I have found on

ASTFactory::addASTChild method of the C++ support library.



Here is the implementation of the method:


			
if (child)
{
if (!currentAST.root)
{
// Make new child the current root
currentAST.root = child;
}
else
{
if (!currentAST.child)
{
// Add new child to current root
currentAST.root->setFirstChild(child);
}
else
{
currentAST.child->setNextSibling(child);
}
}
// Make new child the current child
currentAST.child = child;
currentAST.advanceChildToEnd();
}



The bug is that the lines:


			
{
// Add new child to current root
currentAST.root->setFirstChild(child);
}



will never be executed. I will try to explain it.



The first time you execute the method for an ASTPair, supposing child != NULL,

currentAST.root == NULL, so the next line is executed:


			
currentAST.root = child;



but these line are executed as well:


			
currentAST.child = child;
currentAST.advanceChildToEnd();



so the second time you execute the method currentAST.root != NULL but

currentAST.child != NULL as well,



so the condition (!currentAST.child) will never be true.




I have solved this bug by putting the lines:


			
// Make new child the current child
currentAST.child = child;
currentAST.advanceChildToEnd();



inside the first else clause, so the code modified will be:


			
if (child)
{
if (!currentAST.root)
{
// Make new child the current root
currentAST.root = child;
}
else
{
if (!currentAST.child)
{
// Add new child to current root
currentAST.root->setFirstChild(child);
}
else
{
currentAST.child->setNextSibling(child);
}
// Make new child the current child
currentAST.child = child;
currentAST.advanceChildToEnd();
}
}



I hope this report will be useful.



If you are not agreed with my solution or you think that this is not a bug,

I would like to know why.



David, speedy_f1@hotmail.com    <<Less
About | Sitemap | Contact