Index: Lib/test/string_tests.py =================================================================== --- Lib/test/string_tests.py (revision 76715) +++ Lib/test/string_tests.py (working copy) @@ -185,6 +185,9 @@ self.checkequal(-1, '', 'find', 'xx', 1, 1) self.checkequal(-1, '', 'find', 'xx', sys.maxint, 0) + # issue 7458 + self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0) + # For a variety of combinations, # verify that str.find() matches __contains__ # and that the found substring is really at that location @@ -230,6 +233,9 @@ self.checkraises(TypeError, 'hello', 'rfind') self.checkraises(TypeError, 'hello', 'rfind', 42) + # issue 7458 + self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0) + def test_index(self): self.checkequal(0, 'abcdefghiabc', 'index', '') self.checkequal(3, 'abcdefghiabc', 'index', 'def') Index: Objects/stringlib/find.h =================================================================== --- Objects/stringlib/find.h (revision 76715) +++ Objects/stringlib/find.h (working copy) @@ -33,13 +33,13 @@ Py_ssize_t offset) { /* XXX - create reversefastsearch helper! */ + if (str_len < 0) + return -1; if (sub_len == 0) { - if (str_len < 0) - return -1; - return str_len + offset; + return str_len + offset; } else { - Py_ssize_t j, pos = -1; - for (j = str_len - sub_len; j >= 0; --j) + Py_ssize_t j, pos = -1; + for (j = str_len - sub_len; j >= 0; --j) if (STRINGLIB_CMP(str+j, sub, sub_len) == 0) { pos = j + offset; break;