Coverity CID 748633 Logically dead code In nsFrameSelection::​DeleteFromDocument()

RESOLVED FIXED in Firefox 57

Status

()

enhancement
--
trivial
RESOLVED FIXED
2 years ago
Last year

People

(Reporter: mats, Assigned: lorena9921)

Tracking

(Blocks 1 bug, {coverity})

Trunk
mozilla57
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox57 fixed)

Details

Attachments

(1 attachment)

Coverity CID 748633 Logically dead code

The indicated dead code may have performed some action; that action will never occur.

In nsFrameSelection::​DeleteFromDocument(): Code can never be reached because of a logical contradiction 


3411nsresult
3412nsFrameSelection::DeleteFromDocument()
3413{
3414  nsresult res;
3415
3416  // If we're already collapsed, then we do nothing (bug 719503).
3417  bool isCollapsed;
3418  int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
3419  if (!mDomSelections[index])
3420    return NS_ERROR_NULL_POINTER;
3421
3422  mDomSelections[index]->GetIsCollapsed( &isCollapsed);
    cond_const: Condition isCollapsed, taking false branch. Now the value of isCollapsed is equal to 0.
3423  if (isCollapsed)
3424  {
3425    return NS_OK;
3426  }
3427
3428  RefPtr<Selection> selection = mDomSelections[index];
3429  for (uint32_t rangeIdx = 0; rangeIdx < selection->RangeCount(); ++rangeIdx) {
3430    RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
3431    res = range->DeleteContents();
3432    if (NS_FAILED(res))
3433      return res;
3434  }
3435
3436  // Collapse to the new location.
3437  // If we deleted one character, then we move back one element.
3438  // FIXME  We don't know how to do this past frame boundaries yet.
    const: At condition isCollapsed, the value of isCollapsed must be equal to 0.
    dead_error_condition: The condition isCollapsed cannot be true.
3439  if (isCollapsed)
    CID 748633 (#1 of 1): Logically dead code (DEADCODE)dead_error_line: Execution cannot reach this statement: this->mDomSelections[index]....
3440    mDomSelections[index]->Collapse(mDomSelections[index]->GetAnchorNode(), mDomSelections[index]->AnchorOffset()-1);
3441  else if (mDomSelections[index]->AnchorOffset() > 0)
3442    mDomSelections[index]->Collapse(mDomSelections[index]->GetAnchorNode(), mDomSelections[index]->AnchorOffset());
3443#ifdef DEBUG
3444  else
3445    printf("Don't know how to set selection back past frame boundary\n");
3446#endif
3447
3448  return NS_OK;
3449}
3450
Could you please assign me to this bug?
Flags: needinfo?(mats)
Comment on attachment 8905217 [details]
Bug 1361548 - Removed unreachable isCollapsed if condition.

https://reviewboard.mozilla.org/r/177004/#review182468

Thanks!

::: commit-message-93dd2:1
(Diff revision 1)
> +Bug 1361548 - Removed unreachable isCollapsed if condition

Please add a period at the end of the sentence.
Also, we usually add the r=<reviewer> at the end of the commit message,
so it looks like this:

Bug 1361548 - Removed unreachable isCollapsed if condition.  r=mats
Attachment #8905217 - Flags: review?(mats) → review+
Assignee: nobody → lorena9921
Flags: needinfo?(mats)
Keywords: checkin-needed
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/0fd16b5ccce0
Removed unreachable isCollapsed if condition. r=mats
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/0fd16b5ccce0
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
You need to log in before you can comment on or make changes to this bug.