if (NS_SUCCEEDED(parent->ChildAt(++indx, *getter_AddRefs(sib))) && sib)
if (NS_SUCCEEDED(parent->ChildAt(++indx, getter_AddRefs(sib))) && sib)
nsresult nsContentIterator::GetNextSibling(nsCOMPtr<nsIContent> aNode,                                            nsCOMPtr<nsIContent> *aSibling,                                            nsVoidArray *aIndexes){  if (!aNode)     return NS_ERROR_NULL_POINTER;  if (!aSibling)     return NS_ERROR_NULL_POINTER;    nsCOMPtr<nsIContent> sib;  nsCOMPtr<nsIContent> parent;  PRInt32              indx;    if (NS_FAILED(aNode->GetParent(*getter_AddRefs(parent))) || !parent)    return NS_ERROR_FAILURE;  if (aIndexes)  {    NS_ASSERTION(aIndexes->Count() > 0, "ContentIterator stack underflow");    // use the last entry on the Indexes array for the current index    indx = NS_PTR_TO_INT32((*aIndexes)[aIndexes->Count()-1]);  }  else indx = mCachedIndex;    // reverify that the index of the current node hasn't changed.  // not super cheap, but a lot cheaper than IndexOf(), and still O(1).  // ignore result this time - the index may now be out of range.  (void) parent->ChildAt(indx, *getter_AddRefs(sib)); // sib defaults to nsnull  if (sib != aNode)  {    // someone changed our index - find the new index the painful way    if (NS_FAILED(parent->IndexOf(aNode,indx)))      return NS_ERROR_FAILURE;  }  // indx is now canonically correct  if (NS_SUCCEEDED(parent->ChildAt(++indx, *getter_AddRefs(sib))) && sib)  {    *aSibling = sib;    // update index cache    if (aIndexes)    {      aIndexes->ReplaceElementAt(NS_INT32_TO_PTR(indx),aIndexes->Count()-1);    }    else mCachedIndex = indx;  }  else if (parent != mCommonParent)  {    if (aIndexes)    {      // pop node off the stack, go up one level and return parent or fail.      // Don't leave the index empty, especially if we're      // returning NULL.  This confuses other parts of the code.      if (aIndexes->Count() > 1)        aIndexes->RemoveElementAt(aIndexes->Count()-1);    }    return GetNextSibling(parent, aSibling, aIndexes);  }  else  {    *aSibling = nsnull;    // ok to leave cache out of date here?  }    return NS_OK;}