Changeset 3822


Ignore:
Timestamp:
09/16/03 16:54:30 (19 years ago)
Author:
piso
Message:

getEndOfOutput(): bulletproofing around accesses to posEndOfOutput.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/CommandInterpreter.java

    r1837 r3822  
    33 *
    44 * Copyright (C) 1998-2003 Peter Graves
    5  * $Id: CommandInterpreter.java,v 1.18 2003-05-16 17:43:01 piso Exp $
     5 * $Id: CommandInterpreter.java,v 1.19 2003-09-16 16:54:30 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    8989    public final synchronized Position getEndOfOutput()
    9090    {
     91        if (posEndOfOutput != null) {
     92            if (posEndOfOutput.getOffset() > posEndOfOutput.getLineLength()) {
     93                Log.debug("posEndOfOutput adjusting offset");
     94                posEndOfOutput.setOffset(posEndOfOutput.getLineLength());
     95            }
     96        }
    9197        return posEndOfOutput;
    9298    }
     
    133139        final Editor editor = Editor.currentEditor();
    134140        final Line dotLine = editor.getDotLine();
    135         if (posEndOfOutput == null) {
     141        if (getEndOfOutput() == null) {
    136142            // Ignore input before first prompt is displayed.
    137143            dotLine.setText("");
     
    217223    {
    218224        Editor editor = Editor.currentEditor();
    219         if (editor.getMark() != null || posEndOfOutput == null ||
     225        if (editor.getMark() != null || getEndOfOutput() == null ||
    220226            editor.getDot().isBefore(posEndOfOutput)) {
    221227            // There's a marked block, or we're not at the command line.
     
    267273    protected void backspace()
    268274    {
    269         if (posEndOfOutput == null)
     275        if (getEndOfOutput() == null)
    270276            return;
    271277        boolean ok = true;
     
    300306    private void getInputFromHistory(int direction)
    301307    {
    302         if (posEndOfOutput == null) {
     308        if (getEndOfOutput() == null) {
    303309            // No prompt yet.
    304310            return;
     
    313319            history.reset();
    314320
    315         Position begin = posEndOfOutput.copy();
     321        Position begin = getEndOfOutput().copy();
    316322        Position end = getEnd();
    317323        Region r = new Region(editor.getBuffer(), begin, end);
     
    329335            CompoundEdit compoundEdit = beginCompoundEdit();
    330336            editor.addUndo(SimpleEdit.MOVE);
    331             editor.setDot(posEndOfOutput.copy());
     337            editor.setDot(getEndOfOutput().copy());
    332338            editor.setMark(getEnd());
    333339            editor.deleteRegion();
     
    340346            resetUndo();
    341347        }
    342         for (Line line = posEndOfOutput.getLine(); line != null; line = line.next())
     348        for (Line line = getEndOfOutput().getLine(); line != null; line = line.next())
    343349            line.setFlags(STATE_INPUT);
    344350        editor.setCurrentCommand(COMMAND_HISTORY);
     
    361367                    renumber();
    362368                enforceOutputLimit(Property.SHELL_OUTPUT_LIMIT);
    363                 posEndOfOutput = pos.copy();
     369                setEndOfOutput(pos.copy());
    364370            } else {
    365371                setText(s);
    366                 posEndOfOutput = getEnd().copy();
     372                setEndOfOutput(getEnd().copy());
    367373            }
    368374        }
Note: See TracChangeset for help on using the changeset viewer.