Skip to content

Commit

Permalink
Merge pull request #4524 from MartinNowak/fix14341
Browse files Browse the repository at this point in the history
Merge pull request #4451 from WalterBright/fix14220
  • Loading branch information
WalterBright committed Mar 28, 2015
2 parents 9edd222 + f37749d commit 2e32d48
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/backend/cod2.c
@@ -1,5 +1,5 @@
// Copyright (C) 1984-1998 by Symantec
// Copyright (C) 2000-2013 by Digital Mars
// Copyright (C) 2000-2015 by Digital Mars
// All Rights Reserved
// http://www.digitalmars.com
// Written by Walter Bright
Expand Down Expand Up @@ -1208,6 +1208,7 @@ code *cdmul(elem *e,regm_t *pretregs)
{ cg = cat(cg, getregs(mAX));
cg = genc2(cg,0xC1,grex | modregrm(3,5,AX),shpre); // SHR EAX,shpre
}
cg = cat(cg, getregs(mDX));
cg = movregconst(cg, DX, m, (sz == 8) ? 0x40 : 0); // MOV EDX,m
cg = cat(cg, getregs(mDX | mAX));
cg = gen2(cg,0xF7,grex | modregrmx(3,4,DX)); // MUL EDX
Expand Down
37 changes: 37 additions & 0 deletions test/runnable/mars1.d
Expand Up @@ -1278,6 +1278,42 @@ int test13969(const S13969* f) {
return 0 % ((f.y > 0) ? f.x / f.y : f.x / -f.y);
}

////////////////////////////////////////////////////////////////////////

void test14220()
{
auto a = toString(14);

printf("a.ptr = %p, a.length = %d\n", a.ptr, cast(int)a.length);
return;
}

auto toString(int value)
{
uint mValue = value;

char[int.sizeof * 3] buffer = void;
size_t index = buffer.length;

do
{
uint div = cast(int)(mValue / 10);
char mod = mValue % 10 + '0';
buffer[--index] = mod; // Line 22
mValue = div;
} while (mValue);

//printf("buffer.ptr = %p, index = %d\n", buffer.ptr, cast(int)index);
return dup(buffer[index .. $]);
}

char[] dup(char[] a)
{
//printf("a.ptr = %p, a.length = %d\n", a.ptr, cast(int)a.length);
a[0] = 1; // segfault
return a;
}

////////////////////////////////////////////////////////////////////////

int main()
Expand Down Expand Up @@ -1320,6 +1356,7 @@ int main()
test9449();
test12057();
test13784();
test14220();
printf("Success\n");
return 0;
}

0 comments on commit 2e32d48

Please sign in to comment.