]> granicus.if.org Git - python/commitdiff
[Bug #741171] pdb crashes when enabling a non-existing breakpoint
authorAndrew M. Kuchling <amk@amk.ca>
Thu, 22 May 2003 14:46:12 +0000 (14:46 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Thu, 22 May 2003 14:46:12 +0000 (14:46 +0000)
Check the supplied breakpoint number more carefully.
(Incompatibility: before this patch, "enable -1" would enable
the last breakpoint on the list; now -1 is not a legal ID.  Not sure
anyone would ever use negative indices...)

2.2 bugfix candidate, assuming making -1 illegal isn't considered a problem.

Lib/pdb.py

index c4d789eb2d784bf289ce36df44ed0ab15da84af7..ae2fab6c56f309996591419e1a7d65a6f9fd0440 100755 (executable)
@@ -375,14 +375,34 @@ class Pdb(bdb.Bdb, cmd.Cmd):
     def do_enable(self, arg):
         args = arg.split()
         for i in args:
-            bp = bdb.Breakpoint.bpbynumber[int(i)]
+            try:
+                i = int(i)
+            except ValueError:
+                print 'Breakpoint index %r is not a number' % i
+                continue
+
+            if not (0 <= i < len(bdb.Breakpoint.bpbynumber)):
+                print 'No breakpoint numbered', i
+                continue
+
+            bp = bdb.Breakpoint.bpbynumber[i]
             if bp:
                 bp.enable()
 
     def do_disable(self, arg):
         args = arg.split()
         for i in args:
-            bp = bdb.Breakpoint.bpbynumber[int(i)]
+            try:
+                i = int(i)
+            except ValueError:
+                print 'Breakpoint index %r is not a number' % i
+                continue
+            
+            if not (0 <= i < len(bdb.Breakpoint.bpbynumber)):
+                print 'No breakpoint numbered', i
+                continue
+
+            bp = bdb.Breakpoint.bpbynumber[i]
             if bp:
                 bp.disable()