direct-io.hg

changeset 12326:14dc20d98ee1

[PYGRUB] Fix a few bounds violations in pygrub's command-line editor.
Don't step off the end of the line, or delete characters that aren't there.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Thu Nov 09 14:23:24 2006 +0000 (2006-11-09)
parents 72579f0cdaf7
children ddc4bc24f07c
files tools/pygrub/src/pygrub
line diff
     1.1 --- a/tools/pygrub/src/pygrub	Thu Nov 09 14:11:11 2006 +0000
     1.2 +++ b/tools/pygrub/src/pygrub	Thu Nov 09 14:23:24 2006 +0000
     1.3 @@ -113,17 +113,21 @@ class GrubLineEditor(curses.textpad.Text
     1.4          elif ch == curses.ascii.SOH:  # ^a
     1.5              self.pos = 0
     1.6          elif ch in (curses.ascii.STX,curses.KEY_LEFT):
     1.7 -            self.pos -= 1
     1.8 +            if self.pos > 0:
     1.9 +                self.pos -= 1
    1.10          elif ch in (curses.ascii.BS,curses.KEY_BACKSPACE):
    1.11              if self.pos > 0:
    1.12                  self.pos -= 1
    1.13 -                self.line.pop(self.pos)
    1.14 +                if self.pos < len(self.line):
    1.15 +                    self.line.pop(self.pos)
    1.16          elif ch == curses.ascii.EOT:                           # ^d
    1.17 -            self.line.pop(self.pos)
    1.18 +            if self.pos < len(self.line):
    1.19 +                self.line.pop(self.pos)
    1.20          elif ch == curses.ascii.ENQ:                           # ^e
    1.21              self.pos = len(self.line)
    1.22          elif ch in (curses.ascii.ACK, curses.KEY_RIGHT):
    1.23 -            self.pos +=1
    1.24 +            if self.pos < len(self.line):
    1.25 +                self.pos +=1
    1.26          elif ch == curses.ascii.VT:                            # ^k
    1.27              self.line = self.line[:self.pos]
    1.28          else: