Menu

#2517 CellBuffer: `LineEnd(line)` maybe negative

Bug
open
Scintilla (839)
5
16 hours ago
16 hours ago
Zufu Liu
No

When line is negative, cb.LineEnd(line) is negative which is less than cb.LineStart(line), I think it's worth to keep cb.LineEnd(line) >= cb.LineStart(line) always true, so line length without EOL computed with cb.LineStart(line) - cb.LineEnd(line) is always nonnegative.

Message::PositionFromLine has similar inconsistent: cb.LineStart(line + 1) >= cb.LineStart(line) is true, but PositionFromLine(line + 1) >= PositionFromLine(line) may not always true, so line length computed with PositionFromLine(line + 1) - PositionFromLine(line) may not equals to Message::LineLength(line), which is always nonnegative.

Message::LineLength: can simplidied as following or remove theLineFromUPtr(wParam) compare, as pdoc->LineStart() clamp the value.

case Message::LineLength:
    if ((LineFromUPtr(wParam) < 0) ||
            (LineFromUPtr(wParam) > pdoc->LinesTotal()))
        return 0;
    return pdoc->LineStart(LineFromUPtr(wParam) + 1) - pdoc->LineStart(LineFromUPtr(wParam));

Discussion


Log in to post a comment.