grep: avoid infinite loop when trailing newline is missing
authorMatt Mackall <mpm@selenic.com>
Thu, 23 Oct 2008 14:56:16 -0500
changeset 7230 261a9f47b44b
parent 7229 7946503ec76e
child 7231 8e7130a10f3b
grep: avoid infinite loop when trailing newline is missing
mercurial/commands.py
--- a/mercurial/commands.py	Sun Oct 19 19:12:07 2008 +0200
+++ b/mercurial/commands.py	Thu Oct 23 14:56:16 2008 -0500
@@ -1094,9 +1094,9 @@
             mstart, mend = match.span()
             linenum += body.count('\n', begin, mstart) + 1
             lstart = body.rfind('\n', begin, mstart) + 1 or begin
-            lend = body.find('\n', mend)
+            begin = body.find('\n', mend) + 1 or len(body)
+            lend = begin - 1
             yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
-            begin = lend + 1
 
     class linestate(object):
         def __init__(self, line, linenum, colstart, colend):