Skip to content

Commit

Permalink
Fix issue 20366 - programming bug in ctfe foreach_rverse code
Browse files Browse the repository at this point in the history
Index is not decremented which causes bounds checking error.
  • Loading branch information
SSoulaimane committed Nov 7, 2019
1 parent 37a0434 commit 5ed5704
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -7218,6 +7218,7 @@ private Expression foreachApplyUtf(UnionExp* pue, InterState* istate, Expression
char x = cast(char)r.isIntegerExp().getInteger();
if ((x & 0xC0) != 0x80)
break;
--indx;
++buflen;
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/runnable/interpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,20 @@ void test15681()

/************************************************/

auto test20366()
{
const(char)[] s = ['h', 'e', 'l', '\xef', '\xbd', '\x8c', 'o'];

foreach_reverse (dchar c; s)
{
}

return true;
}
static assert(test20366());

/************************************************/

int main()
{
test1();
Expand Down Expand Up @@ -3628,6 +3642,7 @@ int main()
test14140();
test14862();
test15681();
test20366();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 5ed5704

Please sign in to comment.