Commit 9984a5bc authored by Russ Cox's avatar Russ Cox

cmd/cc: grow some global arrays

Avoids global array buffer overflows if they are
indexed using some of the values between NTYPE
and NALLTYPE.  It is entirely likely that not all of these
are necessary, but this is the C compiler and not worth
worrying much about.  This change takes up only a
few more bytes of memory and makes the behavior
deterministic.

Fixes #3078.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5693052
parent 91bdbf59
...@@ -517,8 +517,8 @@ EXTERN int thechar; ...@@ -517,8 +517,8 @@ EXTERN int thechar;
EXTERN char* thestring; EXTERN char* thestring;
EXTERN Type* thisfn; EXTERN Type* thisfn;
EXTERN int32 thunk; EXTERN int32 thunk;
EXTERN Type* types[NTYPE]; EXTERN Type* types[NALLTYPES];
EXTERN Type* fntypes[NTYPE]; EXTERN Type* fntypes[NALLTYPES];
EXTERN Node* initlist; EXTERN Node* initlist;
EXTERN Term term[NTERM]; EXTERN Term term[NTERM];
EXTERN int nterm; EXTERN int nterm;
......
...@@ -96,7 +96,7 @@ Node* nodmmv; ...@@ -96,7 +96,7 @@ Node* nodmmv;
Node* nodvasop; Node* nodvasop;
char etconv[NTYPE]; /* for _vasop */ char etconv[NALLTYPES]; /* for _vasop */
Init initetconv[] = Init initetconv[] =
{ {
TCHAR, 1, 0, TCHAR, 1, 0,
......
...@@ -46,7 +46,7 @@ struct Gtab ...@@ -46,7 +46,7 @@ struct Gtab
}; };
Ftab ftabinit[OEND]; Ftab ftabinit[OEND];
Gtab gtabinit[NTYPE]; Gtab gtabinit[NALLTYPES];
int int
isfunct(Node *n) isfunct(Node *n)
...@@ -350,7 +350,7 @@ bad: ...@@ -350,7 +350,7 @@ bad:
diag(Z, "dclfunct bad %T %s\n", t, s->name); diag(Z, "dclfunct bad %T %s\n", t, s->name);
} }
Gtab gtabinit[NTYPE] = Gtab gtabinit[NALLTYPES] =
{ {
TCHAR, "c", TCHAR, "c",
TUCHAR, "uc", TUCHAR, "uc",
......
...@@ -1538,92 +1538,92 @@ uchar logrel[12] = ...@@ -1538,92 +1538,92 @@ uchar logrel[12] =
OEQ, ONE, OLS, OLS, OLO, OLO, OHS, OHS, OHI, OHI, OEQ, ONE, OLS, OLS, OLO, OLO, OHS, OHS, OHI, OHI,
}; };
uchar typei[NTYPE]; uchar typei[NALLTYPES];
int typeiinit[] = int typeiinit[] =
{ {
TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TVLONG, TUVLONG, -1, TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TVLONG, TUVLONG, -1,
}; };
uchar typeu[NTYPE]; uchar typeu[NALLTYPES];
int typeuinit[] = int typeuinit[] =
{ {
TUCHAR, TUSHORT, TUINT, TULONG, TUVLONG, TIND, -1, TUCHAR, TUSHORT, TUINT, TULONG, TUVLONG, TIND, -1,
}; };
uchar typesuv[NTYPE]; uchar typesuv[NALLTYPES];
int typesuvinit[] = int typesuvinit[] =
{ {
TVLONG, TUVLONG, TSTRUCT, TUNION, -1, TVLONG, TUVLONG, TSTRUCT, TUNION, -1,
}; };
uchar typeilp[NTYPE]; uchar typeilp[NALLTYPES];
int typeilpinit[] = int typeilpinit[] =
{ {
TINT, TUINT, TLONG, TULONG, TIND, -1 TINT, TUINT, TLONG, TULONG, TIND, -1
}; };
uchar typechl[NTYPE]; uchar typechl[NALLTYPES];
uchar typechlv[NTYPE]; uchar typechlv[NALLTYPES];
uchar typechlvp[NTYPE]; uchar typechlvp[NALLTYPES];
int typechlinit[] = int typechlinit[] =
{ {
TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, -1, TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, -1,
}; };
uchar typechlp[NTYPE]; uchar typechlp[NALLTYPES];
int typechlpinit[] = int typechlpinit[] =
{ {
TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TIND, -1, TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TIND, -1,
}; };
uchar typechlpfd[NTYPE]; uchar typechlpfd[NALLTYPES];
int typechlpfdinit[] = int typechlpfdinit[] =
{ {
TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TFLOAT, TDOUBLE, TIND, -1, TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TFLOAT, TDOUBLE, TIND, -1,
}; };
uchar typec[NTYPE]; uchar typec[NALLTYPES];
int typecinit[] = int typecinit[] =
{ {
TCHAR, TUCHAR, -1 TCHAR, TUCHAR, -1
}; };
uchar typeh[NTYPE]; uchar typeh[NALLTYPES];
int typehinit[] = int typehinit[] =
{ {
TSHORT, TUSHORT, -1, TSHORT, TUSHORT, -1,
}; };
uchar typeil[NTYPE]; uchar typeil[NALLTYPES];
int typeilinit[] = int typeilinit[] =
{ {
TINT, TUINT, TLONG, TULONG, -1, TINT, TUINT, TLONG, TULONG, -1,
}; };
uchar typev[NTYPE]; uchar typev[NALLTYPES];
int typevinit[] = int typevinit[] =
{ {
TVLONG, TUVLONG, -1, TVLONG, TUVLONG, -1,
}; };
uchar typefd[NTYPE]; uchar typefd[NALLTYPES];
int typefdinit[] = int typefdinit[] =
{ {
TFLOAT, TDOUBLE, -1, TFLOAT, TDOUBLE, -1,
}; };
uchar typeaf[NTYPE]; uchar typeaf[NALLTYPES];
int typeafinit[] = int typeafinit[] =
{ {
TFUNC, TARRAY, -1, TFUNC, TARRAY, -1,
}; };
uchar typesu[NTYPE]; uchar typesu[NALLTYPES];
int typesuinit[] = int typesuinit[] =
{ {
TSTRUCT, TUNION, -1, TSTRUCT, TUNION, -1,
}; };
int32 tasign[NTYPE]; int32 tasign[NALLTYPES];
Init tasigninit[] = Init tasigninit[] =
{ {
TCHAR, BNUMBER, 0, TCHAR, BNUMBER, 0,
...@@ -1644,7 +1644,7 @@ Init tasigninit[] = ...@@ -1644,7 +1644,7 @@ Init tasigninit[] =
-1, 0, 0, -1, 0, 0,
}; };
int32 tasadd[NTYPE]; int32 tasadd[NALLTYPES];
Init tasaddinit[] = Init tasaddinit[] =
{ {
TCHAR, BNUMBER, 0, TCHAR, BNUMBER, 0,
...@@ -1663,7 +1663,7 @@ Init tasaddinit[] = ...@@ -1663,7 +1663,7 @@ Init tasaddinit[] =
-1, 0, 0, -1, 0, 0,
}; };
int32 tcast[NTYPE]; int32 tcast[NALLTYPES];
Init tcastinit[] = Init tcastinit[] =
{ {
TCHAR, BNUMBER|BIND|BVOID, 0, TCHAR, BNUMBER|BIND|BVOID, 0,
...@@ -1685,7 +1685,7 @@ Init tcastinit[] = ...@@ -1685,7 +1685,7 @@ Init tcastinit[] =
-1, 0, 0, -1, 0, 0,
}; };
int32 tadd[NTYPE]; int32 tadd[NALLTYPES];
Init taddinit[] = Init taddinit[] =
{ {
TCHAR, BNUMBER|BIND, 0, TCHAR, BNUMBER|BIND, 0,
...@@ -1704,7 +1704,7 @@ Init taddinit[] = ...@@ -1704,7 +1704,7 @@ Init taddinit[] =
-1, 0, 0, -1, 0, 0,
}; };
int32 tsub[NTYPE]; int32 tsub[NALLTYPES];
Init tsubinit[] = Init tsubinit[] =
{ {
TCHAR, BNUMBER, 0, TCHAR, BNUMBER, 0,
...@@ -1723,7 +1723,7 @@ Init tsubinit[] = ...@@ -1723,7 +1723,7 @@ Init tsubinit[] =
-1, 0, 0, -1, 0, 0,
}; };
int32 tmul[NTYPE]; int32 tmul[NALLTYPES];
Init tmulinit[] = Init tmulinit[] =
{ {
TCHAR, BNUMBER, 0, TCHAR, BNUMBER, 0,
...@@ -1741,7 +1741,7 @@ Init tmulinit[] = ...@@ -1741,7 +1741,7 @@ Init tmulinit[] =
-1, 0, 0, -1, 0, 0,
}; };
int32 tand[NTYPE]; int32 tand[NALLTYPES];
Init tandinit[] = Init tandinit[] =
{ {
TCHAR, BINTEGER, 0, TCHAR, BINTEGER, 0,
...@@ -1757,7 +1757,7 @@ Init tandinit[] = ...@@ -1757,7 +1757,7 @@ Init tandinit[] =
-1, 0, 0, -1, 0, 0,
}; };
int32 trel[NTYPE]; int32 trel[NALLTYPES];
Init trelinit[] = Init trelinit[] =
{ {
TCHAR, BNUMBER, 0, TCHAR, BNUMBER, 0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment