# HG changeset patch # User Paul Boddie # Date 1481567512 -3600 # Node ID 887f9d80a1370ec3279ba29ed79ee17bb9d94340 # Parent d11750cc8bf3ff8e16a4f8af467337be9aaf424c Fixed the substring length calculation for negative step values. diff -r d11750cc8bf3 -r 887f9d80a137 templates/native/str.c --- a/templates/native/str.c Mon Dec 12 18:43:29 2016 +0100 +++ b/templates/native/str.c Mon Dec 12 19:31:52 2016 +0100 @@ -125,7 +125,7 @@ int istep = __load_via_object(step->value, __pos___data__).intvalue; /* Calculate the size of the substring. */ - size_t resultsize = ((iend - istart - 1) / istep) + 1; + size_t resultsize = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1; int to, from; /* Reserve space for a new string. */