if (!parent) res = NS_ERROR_NULL_POINTER; if (NS_SUCCEEDED(res))
if (NS_SUCCEEDED(res) && parent)
NS_IMETHODIMP nsHTMLEditor::InsertBreak(){  nsresult res;  if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }  nsAutoRules beginRulesSniffing(this, kOpInsertBreak, nsIEditor::eNext);  nsCOMPtr<nsIDOMSelection> selection;  PRBool cancel, handled;  // pre-process  res = GetSelection(getter_AddRefs(selection));  if (NS_FAILED(res)) return res;  if (!selection) return NS_ERROR_NULL_POINTER;  nsTextRulesInfo ruleInfo(nsHTMLEditRules::kInsertBreak);  res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);  if (NS_FAILED(res)) return res;  if (!cancel && !handled)  {    // create the new BR node    nsCOMPtr<nsIDOMNode> newNode;    nsAutoString tag("BR");    res = DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));    if (!newNode) res = NS_ERROR_NULL_POINTER; // don't return here, so DidDoAction is called    if (NS_SUCCEEDED(res))    {      // set the selection to the new node      nsCOMPtr<nsIDOMNode>parent;      res = newNode->GetParentNode(getter_AddRefs(parent));      if (!parent) res = NS_ERROR_NULL_POINTER; // don't return here, so DidDoAction is called      if (NS_SUCCEEDED(res))      {        PRInt32 offsetInParent=-1;  // we use the -1 as a marker to see if we need to compute this or not        nsCOMPtr<nsIDOMNode>nextNode;        newNode->GetNextSibling(getter_AddRefs(nextNode));        if (nextNode)        {          nsCOMPtr<nsIDOMCharacterData>nextTextNode;          nextTextNode = do_QueryInterface(nextNode);          if (!nextTextNode) {            nextNode = do_QueryInterface(newNode);          }          else {             offsetInParent=0;           }        }        else {          nextNode = do_QueryInterface(newNode);        }        res = GetSelection(getter_AddRefs(selection));        if (!selection) res = NS_ERROR_NULL_POINTER; // don't return here, so DidDoAction is called        if (NS_SUCCEEDED(res))        {          if (-1==offsetInParent)           {            nextNode->GetParentNode(getter_AddRefs(parent));            res = GetChildOffset(nextNode, parent, offsetInParent);            if (NS_SUCCEEDED(res)) {              res = selection->Collapse(parent, offsetInParent+1);  // +1 to insert just after the break            }          }          else          {            res = selection->Collapse(nextNode, offsetInParent);          }        }      }    }  }  if (!cancel)  {    // post-process, always called if WillInsertBreak didn't return cancel==PR_TRUE    res = mRules->DidDoAction(selection, &ruleInfo, res);  }  return res;}