From e2abd6205dc0c47c0e0e174ab3872246613b1e06 Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 7 Sep 2008 12:50:06 +0000 Subject: [PATCH] * src/SDCCglue.c, src/SDCCast.c: fixed throw of "excess elements" warning for char arrays git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5231 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 5 +++++ src/SDCCast.c | 13 ++++++------- src/SDCCglue.c | 25 ++++++++++++++----------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index a025623f..3b311650 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-09-07 Borut Razem + + * src/SDCCglue.c, src/SDCCast.c: + fixed throw of "excess elements" warning for char arrays + 2008-06-04 Maarten Brock * as/z80/aslist.c (lstsym): changed old K&R to ANSI diff --git a/src/SDCCast.c b/src/SDCCast.c index 4901b9a7..2e6d1f8e 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -852,7 +852,7 @@ processParms (ast *func, /* don't perform integer promotion of explicitly typecasted variable arguments * if sdcc extensions are enabled */ - if (options.std_sdcc && + if (options.std_sdcc && (IS_CAST_OP (*actParm) || (IS_AST_SYM_VALUE (*actParm) && AST_VALUES (*actParm, removedCast)) || (IS_AST_LIT_VALUE (*actParm) && AST_VALUES (*actParm, literalFromCast)))) @@ -1151,7 +1151,7 @@ createIvalCharPtr (ast * sym, sym_link * type, ast * iexpr, ast *rootVal) if (!AST_SYMBOL (rootVal)->islocal || SPEC_STAT (getSpec (type))) return NULL; - for (i=0; iftype); - if (symsize && size>symsize) + if (symsize && size > symsize) { - if (size>(symsize+1)) + if (size > symsize) { char *name = (IS_AST_SYM_VALUE(sym)) ? AST_SYMBOL(sym)->name : ""; @@ -1187,15 +1187,14 @@ createIvalCharPtr (ast * sym, sym_link * type, ast * iexpr, ast *rootVal) size = symsize; } - for (i=0;iival, sym->type); ++noInit; - printIval (sym, sym->type, sym->ival, &tmpBuf); + printIval (sym, sym->type, sym->ival, &tmpBuf, TRUE); --noInit; --noAlloc; dbuf_destroy(&tmpBuf); @@ -785,14 +785,14 @@ printIvalStruct (symbol * sym, sym_link * type, } if (SPEC_STRUCT (type)->type == UNION) { - printIval (sym, sflds->type, iloop, oBuf); + printIval (sym, sflds->type, iloop, oBuf, TRUE); iloop = iloop ? iloop->next : NULL; } else { for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) { if (IS_BITFIELD(sflds->type)) { printIvalBitFields(&sflds, &iloop, oBuf); } else { - printIval (sym, sflds->type, iloop, oBuf); + printIval (sym, sflds->type, iloop, oBuf, TRUE); } } } @@ -806,7 +806,7 @@ printIvalStruct (symbol * sym, sym_link * type, /* printIvalChar - generates initital value for character array */ /*-----------------------------------------------------------------*/ int -printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s) +printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s, bool check) { value *val; unsigned int size = DCL_ELEM (type); @@ -828,6 +828,9 @@ printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * DCL_ELEM (type) = size; } + if (check && DCL_ELEM (val->type) > size) + werror (W_EXCESS_INITIALIZERS, "array of chars", sym->name, sym->lineDef); + printChar (oBuf, SPEC_CVAL (val->etype).v_char, size); return 1; @@ -845,7 +848,7 @@ printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * /*-----------------------------------------------------------------*/ void printIvalArray (symbol * sym, sym_link * type, initList * ilist, - struct dbuf_s * oBuf) + struct dbuf_s * oBuf, bool check) { value *val; initList *iloop; @@ -867,7 +870,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist, } if (printIvalChar (sym, type, (ilist->type == INIT_DEEP ? ilist->init.deep : ilist), - oBuf, SPEC_CVAL (sym->etype).v_char)) + oBuf, SPEC_CVAL (sym->etype).v_char, check)) return; } /* not the special case */ @@ -881,7 +884,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist, werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "array", sym->name); break; } - printIval (sym, type->next, iloop, oBuf); + printIval (sym, type->next, iloop, oBuf, TRUE); } } @@ -1182,7 +1185,7 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * o /* printIval - generates code for initial value */ /*-----------------------------------------------------------------*/ void -printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf) +printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, bool check) { sym_link *itype; @@ -1196,7 +1199,7 @@ printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf /* if this is an array */ if (IS_ARRAY (type)) { - printIvalArray (sym, type, ilist, oBuf); + printIvalArray (sym, type, ilist, oBuf, check); return; } @@ -1313,7 +1316,7 @@ emitStaticSeg (memmap * map, struct dbuf_s * oBuf) dbuf_printf (oBuf, "%s:\n", sym->rname); ++noAlloc; resolveIvalSym (sym->ival, sym->type); - printIval (sym, sym->type, sym->ival, oBuf); + printIval (sym, sym->type, sym->ival, oBuf, map != xinit); --noAlloc; /* if sym is a simple string and sym->ival is a string, WE don't need it anymore */ -- 2.30.2