Branch: Tag:

2014-07-15

2014-07-15 10:56:33 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Optimizer: Fixed bug in foreach with ranges.

The foreach range optimizer didn't handle negative start ranges,
which would cause foreach to index the array out of bounds.

Fixes [bug 7216 (#7216)].

8851:    return v;   ]], 4)    + test_any([[ +  // Check foreach with negative ranges [bug 7216]/[LysLysKOM 20892964]. +  array a = ({ -2, -1, 0, 1, 2 }); +  int total; +  foreach(a, int start) { +  foreach(a[start..], int val) { +  if (!intp(val)) error("Invalid svalue!\n"); +  total += (val + 3)*(start + 3); +  } +  } +  return total; + ]], 15 + 30 + 45 + 56 + 60) +    // do-while   test_any(int e;string t=""; e=0; do{ t+=e; }while(++e<6); return t,"012345";)