Commits

Benjamin Peterson committed 3b13b7c

if start - stop <= 0, return a empty string

Comments (0)

Files changed (2)

pypy/rpython/lltypesystem/rstr.py

     def _ll_stringslice(s1, start, stop):
         lgt = stop - start
         assert start >= 0
-        assert lgt >= 0
+        if lgt <= 0:
+            return s1.empty()
         newstr = s1.malloc(lgt)
         s1.copy_contents(s1, newstr, start, 0, lgt)
         return newstr

pypy/rpython/test/test_rstr.py

             s1 = s[:3]
             s2 = s[3:]
             s3 = s[3:10]
-            return s1+s2 == s and s2+s1 == const('lohel') and s1+s3 == s
+            s4 = s[42:44]
+            return s1+s2 == s and s2+s1 == const('lohel') and s1+s3 == s and s4 == ""
         res = self.interpret(fn, [0])
         assert res