From 9984a5bca403ec14340a05c6fd57fcbefd96f4df Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 23 Feb 2012 22:45:55 -0500 Subject: [PATCH] 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 --- src/cmd/cc/cc.h | 4 ++-- src/cmd/cc/com64.c | 2 +- src/cmd/cc/funct.c | 4 ++-- src/cmd/cc/sub.c | 48 +++++++++++++++++++++++----------------------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/cmd/cc/cc.h b/src/cmd/cc/cc.h index f4632364cf..4c527a2b3d 100644 --- a/src/cmd/cc/cc.h +++ b/src/cmd/cc/cc.h @@ -517,8 +517,8 @@ EXTERN int thechar; EXTERN char* thestring; EXTERN Type* thisfn; EXTERN int32 thunk; -EXTERN Type* types[NTYPE]; -EXTERN Type* fntypes[NTYPE]; +EXTERN Type* types[NALLTYPES]; +EXTERN Type* fntypes[NALLTYPES]; EXTERN Node* initlist; EXTERN Term term[NTERM]; EXTERN int nterm; diff --git a/src/cmd/cc/com64.c b/src/cmd/cc/com64.c index fb7a3f750e..f46fedc16a 100644 --- a/src/cmd/cc/com64.c +++ b/src/cmd/cc/com64.c @@ -96,7 +96,7 @@ Node* nodmmv; Node* nodvasop; -char etconv[NTYPE]; /* for _vasop */ +char etconv[NALLTYPES]; /* for _vasop */ Init initetconv[] = { TCHAR, 1, 0, diff --git a/src/cmd/cc/funct.c b/src/cmd/cc/funct.c index 99477b2b23..0571519871 100644 --- a/src/cmd/cc/funct.c +++ b/src/cmd/cc/funct.c @@ -46,7 +46,7 @@ struct Gtab }; Ftab ftabinit[OEND]; -Gtab gtabinit[NTYPE]; +Gtab gtabinit[NALLTYPES]; int isfunct(Node *n) @@ -350,7 +350,7 @@ bad: diag(Z, "dclfunct bad %T %s\n", t, s->name); } -Gtab gtabinit[NTYPE] = +Gtab gtabinit[NALLTYPES] = { TCHAR, "c", TUCHAR, "uc", diff --git a/src/cmd/cc/sub.c b/src/cmd/cc/sub.c index 98e9f5a4b4..72d671b2f5 100644 --- a/src/cmd/cc/sub.c +++ b/src/cmd/cc/sub.c @@ -1538,92 +1538,92 @@ uchar logrel[12] = OEQ, ONE, OLS, OLS, OLO, OLO, OHS, OHS, OHI, OHI, }; -uchar typei[NTYPE]; +uchar typei[NALLTYPES]; int typeiinit[] = { TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TVLONG, TUVLONG, -1, }; -uchar typeu[NTYPE]; +uchar typeu[NALLTYPES]; int typeuinit[] = { TUCHAR, TUSHORT, TUINT, TULONG, TUVLONG, TIND, -1, }; -uchar typesuv[NTYPE]; +uchar typesuv[NALLTYPES]; int typesuvinit[] = { TVLONG, TUVLONG, TSTRUCT, TUNION, -1, }; -uchar typeilp[NTYPE]; +uchar typeilp[NALLTYPES]; int typeilpinit[] = { TINT, TUINT, TLONG, TULONG, TIND, -1 }; -uchar typechl[NTYPE]; -uchar typechlv[NTYPE]; -uchar typechlvp[NTYPE]; +uchar typechl[NALLTYPES]; +uchar typechlv[NALLTYPES]; +uchar typechlvp[NALLTYPES]; int typechlinit[] = { TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, -1, }; -uchar typechlp[NTYPE]; +uchar typechlp[NALLTYPES]; int typechlpinit[] = { TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TIND, -1, }; -uchar typechlpfd[NTYPE]; +uchar typechlpfd[NALLTYPES]; int typechlpfdinit[] = { TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TFLOAT, TDOUBLE, TIND, -1, }; -uchar typec[NTYPE]; +uchar typec[NALLTYPES]; int typecinit[] = { TCHAR, TUCHAR, -1 }; -uchar typeh[NTYPE]; +uchar typeh[NALLTYPES]; int typehinit[] = { TSHORT, TUSHORT, -1, }; -uchar typeil[NTYPE]; +uchar typeil[NALLTYPES]; int typeilinit[] = { TINT, TUINT, TLONG, TULONG, -1, }; -uchar typev[NTYPE]; +uchar typev[NALLTYPES]; int typevinit[] = { TVLONG, TUVLONG, -1, }; -uchar typefd[NTYPE]; +uchar typefd[NALLTYPES]; int typefdinit[] = { TFLOAT, TDOUBLE, -1, }; -uchar typeaf[NTYPE]; +uchar typeaf[NALLTYPES]; int typeafinit[] = { TFUNC, TARRAY, -1, }; -uchar typesu[NTYPE]; +uchar typesu[NALLTYPES]; int typesuinit[] = { TSTRUCT, TUNION, -1, }; -int32 tasign[NTYPE]; +int32 tasign[NALLTYPES]; Init tasigninit[] = { TCHAR, BNUMBER, 0, @@ -1644,7 +1644,7 @@ Init tasigninit[] = -1, 0, 0, }; -int32 tasadd[NTYPE]; +int32 tasadd[NALLTYPES]; Init tasaddinit[] = { TCHAR, BNUMBER, 0, @@ -1663,7 +1663,7 @@ Init tasaddinit[] = -1, 0, 0, }; -int32 tcast[NTYPE]; +int32 tcast[NALLTYPES]; Init tcastinit[] = { TCHAR, BNUMBER|BIND|BVOID, 0, @@ -1685,7 +1685,7 @@ Init tcastinit[] = -1, 0, 0, }; -int32 tadd[NTYPE]; +int32 tadd[NALLTYPES]; Init taddinit[] = { TCHAR, BNUMBER|BIND, 0, @@ -1704,7 +1704,7 @@ Init taddinit[] = -1, 0, 0, }; -int32 tsub[NTYPE]; +int32 tsub[NALLTYPES]; Init tsubinit[] = { TCHAR, BNUMBER, 0, @@ -1723,7 +1723,7 @@ Init tsubinit[] = -1, 0, 0, }; -int32 tmul[NTYPE]; +int32 tmul[NALLTYPES]; Init tmulinit[] = { TCHAR, BNUMBER, 0, @@ -1741,7 +1741,7 @@ Init tmulinit[] = -1, 0, 0, }; -int32 tand[NTYPE]; +int32 tand[NALLTYPES]; Init tandinit[] = { TCHAR, BINTEGER, 0, @@ -1757,7 +1757,7 @@ Init tandinit[] = -1, 0, 0, }; -int32 trel[NTYPE]; +int32 trel[NALLTYPES]; Init trelinit[] = { TCHAR, BNUMBER, 0, -- 2.50.0