2016-12-12 | Paul Boddie | raw files shortlog changelog graph | Fixed the substring length calculation for negative step values. | |
templates/native/str.c (file) |
1.1 --- a/templates/native/str.c Mon Dec 12 18:43:29 2016 +0100 1.2 +++ b/templates/native/str.c Mon Dec 12 19:31:52 2016 +0100 1.3 @@ -125,7 +125,7 @@ 1.4 int istep = __load_via_object(step->value, __pos___data__).intvalue; 1.5 1.6 /* Calculate the size of the substring. */ 1.7 - size_t resultsize = ((iend - istart - 1) / istep) + 1; 1.8 + size_t resultsize = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1; 1.9 int to, from; 1.10 1.11 /* Reserve space for a new string. */