Skip to content

Commit

Permalink
Merge pull request #2624 from WalterBright/fix4611
Browse files Browse the repository at this point in the history
fix Issue 4611 - stack overflow or ICE(cgcod.c) when static array of str...
  • Loading branch information
braddr committed Oct 6, 2013
2 parents fadd96c + 53645e4 commit 3e87ccd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/backend/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typep_t tsptrdiff, tssize;

targ_size_t type_size(type *t)
{ targ_size_t s;
unsigned long u;
tym_t tyb;

type_debug(t);
Expand Down Expand Up @@ -88,6 +87,7 @@ targ_size_t type_size(type *t)
s = 1;
break;
case TYarray:
{
if (t->Tflags & TFsizeunknown)
{
#if SCPP
Expand All @@ -101,12 +101,18 @@ targ_size_t type_size(type *t)
break;
}
s = type_size(t->Tnext);
u = t->Tdim * (unsigned long) s;
#if TX86 && SCPP
unsigned long u = t->Tdim * (unsigned long) s;
#if SCPP
type_chksize(u);
#elif MARS
if (t->Tdim && ((u / t->Tdim) != s || (long)u < 0))
assert(0); // overflow should have been detected in front end
#else
assert(0);
#endif
s = u;
break;
}
case TYstruct:
t = t->Ttag->Stype; /* find main instance */
/* (for const struct X) */
Expand Down
1 change: 1 addition & 0 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -4010,6 +4010,7 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
tbn->ty == Tarray ||
tbn->ty == Tsarray ||
tbn->ty == Taarray ||
(tbn->ty == Tstruct && (((TypeStruct *)tbn)->sym->sizeok == SIZEOKdone)) ||
tbn->ty == Tclass)
{
/* Only do this for types that don't need to have semantic()
Expand Down
16 changes: 16 additions & 0 deletions test/fail_compilation/fail4611.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail4611.d(15): Error: index 1000000000 overflow for static array
---
*/

struct Vec
{
int x;
}

void main()
{
Vec[1000_000_000] a;
}

0 comments on commit 3e87ccd

Please sign in to comment.