}
if (*sym->rname)
- sprintf (val->name, "%s", sym->rname);
+ {
+ SNPRINTF (val->name, sizeof(val->name), "%s", sym->rname);
+ }
else
- sprintf (val->name, "_%s", sym->name);
-
+ {
+ SNPRINTF (val->name, sizeof(val->name), "_%s", sym->name);
+ }
return val;
}
if ((((long) lit) - lit) == 0)
{
- sprintf (buffer, "%ld", (long) lit);
+ SNPRINTF (buffer, sizeof(buffer), "%ld", (long) lit);
return constVal (buffer);
}
- sprintf (buffer, "%f", lit);
+ SNPRINTF (buffer, sizeof(buffer), "%f", lit);
return constFloatVal (buffer);
}
dest = newValue ();
dest->sym = copySymbol (src->sym);
- strcpy (dest->name, src->name);
+ strncpyz (dest->name, src->name, SDCC_NAME_MAX);
dest->type = (src->type ? copyLinkChain (src->type) : NULL);
dest->etype = (src->type ? getSpec (dest->type) : NULL);
switch (*s)
{
case 'n':
- SPEC_CVAL (val->type).v_int = '\n';
+ SPEC_CVAL (val->type).v_uint = '\n';
break;
case 't':
- SPEC_CVAL (val->type).v_int = '\t';
+ SPEC_CVAL (val->type).v_uint = '\t';
break;
case 'v':
- SPEC_CVAL (val->type).v_int = '\v';
+ SPEC_CVAL (val->type).v_uint = '\v';
break;
case 'b':
- SPEC_CVAL (val->type).v_int = '\b';
+ SPEC_CVAL (val->type).v_uint = '\b';
break;
case 'r':
- SPEC_CVAL (val->type).v_int = '\r';
+ SPEC_CVAL (val->type).v_uint = '\r';
break;
case 'f':
- SPEC_CVAL (val->type).v_int = '\f';
+ SPEC_CVAL (val->type).v_uint = '\f';
break;
case 'a':
- SPEC_CVAL (val->type).v_int = '\a';
+ SPEC_CVAL (val->type).v_uint = '\a';
break;
case '\\':
- SPEC_CVAL (val->type).v_int = '\\';
+ SPEC_CVAL (val->type).v_uint = '\\';
break;
case '\?':
- SPEC_CVAL (val->type).v_int = '\?';
+ SPEC_CVAL (val->type).v_uint = '\?';
break;
case '\'':
- SPEC_CVAL (val->type).v_int = '\'';
+ SPEC_CVAL (val->type).v_uint = '\'';
break;
case '\"':
- SPEC_CVAL (val->type).v_int = '\"';
+ SPEC_CVAL (val->type).v_uint = '\"';
break;
case '0' :
}
if (IS_BITVAR(val->etype)) {
- return (double) SPEC_CVAL (val->etype).v_ulong;
+ return (double) SPEC_CVAL (val->etype).v_uint;
}
if (SPEC_NOUN (val->etype) == V_VOID) {
}
// -(unsigned 3) now really is signed
SPEC_USIGN(val->etype)=0;
+ // -(unsigned char)135 now really is an int
+ if (SPEC_NOUN(val->etype) == V_CHAR) {
+ if (SPEC_CVAL(val->etype).v_int < -128) {
+ SPEC_NOUN(val->etype) = V_INT;
+ }
+ }
return val;
}
/* create a new value */
val = newValue ();
- val->type = copyLinkChain (lval->type);
+ val->type = copyLinkChain (getSize(rval->type) > getSize(lval->type) ?
+ rval->type : lval->type);
val->etype = getSpec (val->type);
switch (op)
int
getNelements (sym_link * type, initList * ilist)
{
- sym_link *etype = getSpec (type);
int i;
if (!ilist)
/* if type is a character array and there is only one
(string) initialiser then get the length of the string */
- if (IS_ARRAY (type) && IS_CHAR (etype) && !ilist->next)
+ if (IS_ARRAY (type) && IS_CHAR (type->next) && !ilist->next)
{
ast *iast = ilist->init.node;
value *v = (iast->type == EX_VALUE ? iast->opval.val : NULL);
if (!v)
{
- werror (W_INIT_WRONG);
+ werror (E_CONST_EXPECTED);
return 0;
}
i++;
ilist = ilist->next;
}
-
return i;
}
val = newValue ();
if (!lval)
- sprintf (buffer, "%s", AST_SYMBOL (arrExpr->left)->rname);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "%s", AST_SYMBOL (arrExpr->left)->rname);
+ }
else
- sprintf (buffer, "%s", lval->name);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "%s", lval->name);
+ }
- sprintf (val->name, "(%s + %d)", buffer,
+ SNPRINTF (val->name, sizeof(val->name), "(%s + %d)", buffer,
(int) AST_LIT_VALUE (arrExpr->right) * size);
val->type = newLink ();
if (SPEC_SCLS (arrExpr->left->etype) == S_CODE)
{
DCL_TYPE (val->type) = CPOINTER;
- DCL_PTR_CONST (val->type) = port->mem.code_ro;
}
else if (SPEC_SCLS (arrExpr->left->etype) == S_XDATA)
DCL_TYPE (val->type) = FPOINTER;
val = newValue ();
if (!lval)
- sprintf (buffer, "%s", AST_SYMBOL (structT)->rname);
+ {
+ SNPRINTF(buffer, sizeof(buffer), "%s", AST_SYMBOL (structT)->rname);
+ }
else
- sprintf (buffer, "%s", lval->name);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "%s", lval->name);
+ }
- sprintf (val->name, "(%s + %d)", buffer,
+ SNPRINTF (val->name, sizeof(val->name), "(%s + %d)", buffer,
(int) sym->offset);
val->type = newLink ();
if (SPEC_SCLS (structT->etype) == S_CODE)
{
DCL_TYPE (val->type) = CPOINTER;
- DCL_PTR_CONST (val->type) = port->mem.code_ro;
}
else if (SPEC_SCLS (structT->etype) == S_XDATA)
DCL_TYPE (val->type) = FPOINTER;
val = newValue ();
- sprintf (val->name, "(%s %c %d)",
+ SNPRINTF (val->name, sizeof(val->name), "(%s %c %d)",
AST_SYMBOL (aexpr)->rname, op,
getSize (type->next) * (int) AST_LIT_VALUE (cnst));
val = newValue ();
- sprintf (val->name, "(%s)",
+ SNPRINTF (val->name, sizeof(val->name), "(%s)",
AST_SYMBOL (aexpr)->rname);
val->type = type;