git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2287
4a8a32a2-be11-0410-ad9d-
d568d2c75423
14 files changed:
#include "port.h"
#include "newalloc.h"
#include "SDCCerr.h"
#include "port.h"
#include "newalloc.h"
#include "SDCCerr.h"
extern int yyerror (char *);
extern FILE *yyin;
extern int yyerror (char *);
extern FILE *yyin;
- sprintf(lbuff,"%d",(int) floatFromVal(cenum)+1);
+ SNPRINTF(lbuff, sizeof(lbuff),
+ "%d",(int) floatFromVal(cenum)+1);
$$ = cenum = constVal(lbuff);
}
else {
$$ = cenum = constVal(lbuff);
}
else {
+ SNPRINTF(lbuff, sizeof(lbuff),
+ "%d",0);
$$ = cenum = constVal(lbuff);
}
}
$$ = cenum = constVal(lbuff);
}
}
ex->values.switchVals.swNum = swLabel ;
/* now create the label */
ex->values.switchVals.swNum = swLabel ;
/* now create the label */
- sprintf(lbuff,"_swBrk_%d",swLabel++);
+ SNPRINTF(lbuff, sizeof(lbuff),
+ "_swBrk_%d",swLabel++);
$<sym>$ = newSymbol(lbuff,NestLevel);
/* put label in the break stack */
STACK_PUSH(breakStack,$<sym>$);
$<sym>$ = newSymbol(lbuff,NestLevel);
/* put label in the break stack */
STACK_PUSH(breakStack,$<sym>$);
while : WHILE { /* create and push the continue , break & body labels */
static int Lblnum = 0 ;
/* continue */
while : WHILE { /* create and push the continue , break & body labels */
static int Lblnum = 0 ;
/* continue */
- sprintf (lbuff,"_whilecontinue_%d",Lblnum);
+ SNPRINTF (lbuff, sizeof(lbuff), "_whilecontinue_%d",Lblnum);
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
- sprintf (lbuff,"_whilebreak_%d",Lblnum);
+ SNPRINTF (lbuff, sizeof(lbuff), "_whilebreak_%d",Lblnum);
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* body */
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* body */
- sprintf (lbuff,"_whilebody_%d",Lblnum++);
+ SNPRINTF (lbuff, sizeof(lbuff), "_whilebody_%d",Lblnum++);
$$ = newSymbol(lbuff,NestLevel);
}
;
$$ = newSymbol(lbuff,NestLevel);
}
;
static int Lblnum = 0 ;
/* continue */
static int Lblnum = 0 ;
/* continue */
- sprintf(lbuff,"_docontinue_%d",Lblnum);
+ SNPRINTF(lbuff, sizeof(lbuff), "_docontinue_%d",Lblnum);
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
- sprintf (lbuff,"_dobreak_%d",Lblnum);
+ SNPRINTF(lbuff, sizeof(lbuff), "_dobreak_%d",Lblnum);
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* do body */
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* do body */
- sprintf (lbuff,"_dobody_%d",Lblnum++);
+ SNPRINTF(lbuff, sizeof(lbuff), "_dobody_%d",Lblnum++);
$$ = newSymbol (lbuff,NestLevel);
}
;
$$ = newSymbol (lbuff,NestLevel);
}
;
static int Lblnum = 0 ;
/* continue */
static int Lblnum = 0 ;
/* continue */
- sprintf (lbuff,"_forcontinue_%d",Lblnum);
+ SNPRINTF(lbuff, sizeof(lbuff), "_forcontinue_%d",Lblnum);
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
/* break */
- sprintf (lbuff,"_forbreak_%d",Lblnum);
+ SNPRINTF(lbuff, sizeof(lbuff), "_forbreak_%d",Lblnum);
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* body */
STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
/* body */
- sprintf (lbuff,"_forbody_%d",Lblnum);
+ SNPRINTF(lbuff, sizeof(lbuff), "_forbody_%d",Lblnum);
$$ = newSymbol(lbuff,NestLevel);
/* condition */
$$ = newSymbol(lbuff,NestLevel);
/* condition */
- sprintf (lbuff,"_forcond_%d",Lblnum++);
+ SNPRINTF(lbuff, sizeof(lbuff), "_forcond_%d",Lblnum++);
STACK_PUSH(forStack,newSymbol(lbuff,NestLevel));
}
;
STACK_PUSH(forStack,newSymbol(lbuff,NestLevel));
}
;
ebb->entryLabel = ic->argLabel.label;
else
{
ebb->entryLabel = ic->argLabel.label;
else
{
- sprintf (buffer, "_eBBlock%d", eBBNum++);
+ SNPRINTF (buffer, sizeof(buffer), "_eBBlock%d", eBBNum++);
ebb->entryLabel = newSymbol (buffer, 1);
ebb->entryLabel->key = labelKey++;
}
ebb->entryLabel = newSymbol (buffer, 1);
ebb->entryLabel->key = labelKey++;
}
- sprintf (name, "_str_%d", charLbl++);
+ SNPRINTF (name, sizeof(name), "_str_%d", charLbl++);
sym = newSymbol (name, 0); /* make it @ level 0 */
strncpyz (sym->rname, name, SDCC_NAME_MAX);
sym = newSymbol (name, 0); /* make it @ level 0 */
strncpyz (sym->rname, name, SDCC_NAME_MAX);
case SIZEOF: /* evaluate wihout code generation */
/* change the type to a integer */
tree->type = EX_VALUE;
case SIZEOF: /* evaluate wihout code generation */
/* change the type to a integer */
tree->type = EX_VALUE;
- sprintf (buffer, "%d", (getSize (tree->right->ftype)));
+ SNPRINTF(buffer, sizeof(buffer), "%d", (getSize (tree->right->ftype)));
tree->opval.val = constVal (buffer);
tree->right = tree->left = NULL;
TETYPE (tree) = getSpec (TTYPE (tree) =
tree->opval.val = constVal (buffer);
tree->right = tree->left = NULL;
TETYPE (tree) = getSpec (TTYPE (tree) =
- sprintf (buffer, "%d", typeofv);
+ SNPRINTF (buffer, sizeof(buffer), "%d", typeofv);
tree->opval.val = constVal (buffer);
tree->right = tree->left = NULL;
TETYPE (tree) = getSpec (TTYPE (tree) =
tree->opval.val = constVal (buffer);
tree->right = tree->left = NULL;
TETYPE (tree) = getSpec (TTYPE (tree) =
checkTypeSanity(type, "(sizeof)");
/* get the size and convert it to character */
checkTypeSanity(type, "(sizeof)");
/* get the size and convert it to character */
- sprintf (buff, "%d", getSize (type));
+ SNPRINTF (buff, sizeof(buff), "%d", getSize (type));
/* now convert into value */
return constVal (buff);
/* now convert into value */
return constVal (buff);
static int localLbl = 0;
symbol *localLabel;
static int localLbl = 0;
symbol *localLabel;
- sprintf (buffer, "_and_%d", localLbl++);
+ SNPRINTF(buffer, sizeof(buffer), "_and_%d", localLbl++);
localLabel = newSymbol (buffer, NestLevel);
tree->left = backPatchLabels (tree->left, localLabel, falseLabel);
localLabel = newSymbol (buffer, NestLevel);
tree->left = backPatchLabels (tree->left, localLabel, falseLabel);
static int localLbl = 0;
symbol *localLabel;
static int localLbl = 0;
symbol *localLabel;
- sprintf (buffer, "_or_%d", localLbl++);
+ SNPRINTF(buffer, sizeof(buffer), "_or_%d", localLbl++);
localLabel = newSymbol (buffer, NestLevel);
tree->left = backPatchLabels (tree->left, trueLabel, localLabel);
localLabel = newSymbol (buffer, NestLevel);
tree->left = backPatchLabels (tree->left, trueLabel, localLabel);
label = newSymbol (label->name, label->level);
/* change the name before putting it in add _ */
label = newSymbol (label->name, label->level);
/* change the name before putting it in add _ */
- sprintf (name, "%s", label->name);
+ SNPRINTF(name, sizeof(name), "%s", label->name);
/* put the label in the LabelSymbol table */
/* but first check if a label of the same */
/* put the label in the LabelSymbol table */
/* but first check if a label of the same */
}
/* create the case label */
}
/* create the case label */
- sprintf (caseLbl, "_case_%d_%d",
+ SNPRINTF(caseLbl, sizeof(caseLbl),
+ "_case_%d_%d",
swStat->values.switchVals.swNum,
(int) floatFromVal (caseVal->opval.val));
swStat->values.switchVals.swNum,
(int) floatFromVal (caseVal->opval.val));
swStat->values.switchVals.swDefault = 1;
/* create the label */
swStat->values.switchVals.swDefault = 1;
/* create the label */
- sprintf (defLbl, "_default_%d", swStat->values.switchVals.swNum);
+ SNPRINTF (defLbl, sizeof(defLbl),
+ "_default_%d", swStat->values.switchVals.swNum);
return createLabel (newSymbol (defLbl, 0), stmnt);
}
return createLabel (newSymbol (defLbl, 0), stmnt);
}
}
/* create the labels */
}
/* create the labels */
- sprintf (buffer, "_iffalse_%d", Lblnum);
+ SNPRINTF (buffer, sizeof(buffer), "_iffalse_%d", Lblnum);
ifFalse = newSymbol (buffer, NestLevel);
/* if no else body then end == false */
if (!elseBody)
ifEnd = ifFalse;
else
{
ifFalse = newSymbol (buffer, NestLevel);
/* if no else body then end == false */
if (!elseBody)
ifEnd = ifFalse;
else
{
- sprintf (buffer, "_ifend_%d", Lblnum);
+ SNPRINTF(buffer, sizeof(buffer), "_ifend_%d", Lblnum);
ifEnd = newSymbol (buffer, NestLevel);
}
ifEnd = newSymbol (buffer, NestLevel);
}
- sprintf (buffer, "_iftrue_%d", Lblnum);
+ SNPRINTF (buffer, sizeof(buffer), "_iftrue_%d", Lblnum);
ifTrue = newSymbol (buffer, NestLevel);
Lblnum++;
ifTrue = newSymbol (buffer, NestLevel);
Lblnum++;
name->stack = SPEC_STAK (fetype) = stack;
/* name needs to be mangled */
name->stack = SPEC_STAK (fetype) = stack;
/* name needs to be mangled */
- sprintf (name->rname, "%s%s", port->fun_prefix, name->name);
+ SNPRINTF (name->rname, sizeof(name->rname), "%s%s", port->fun_prefix, name->name);
body = resolveSymbols (body); /* resolve the symbols */
body = decorateType (body); /* propagateType & do semantic checks */
body = resolveSymbols (body); /* resolve the symbols */
body = decorateType (body); /* propagateType & do semantic checks */
// create a new "XINIT (CODE)" symbol, that will be emitted later
newSym=copySymbol (sym);
SPEC_OCLS(newSym->etype)=xinit;
// create a new "XINIT (CODE)" symbol, that will be emitted later
newSym=copySymbol (sym);
SPEC_OCLS(newSym->etype)=xinit;
- sprintf (newSym->name, "__xinit_%s", sym->name);
- sprintf (newSym->rname,"__xinit_%s", sym->rname);
+ SNPRINTF (newSym->name, sizeof(newSym->name), "__xinit_%s", sym->name);
+ SNPRINTF (newSym->rname, sizeof(newSym->rname), "__xinit_%s", sym->rname);
SPEC_CONST(newSym->etype)=1;
SPEC_STAT(newSym->etype)=1;
resolveIvalSym(newSym->ival);
SPEC_CONST(newSym->etype)=1;
SPEC_STAT(newSym->etype)=1;
resolveIvalSym(newSym->ival);
#if 0 // temporary disabled, leaving the warning as a reminder
if (warnings) {
#if 0 // temporary disabled, leaving the warning as a reminder
if (warnings) {
- sprintf (message, "for %s %s in %s",
+ SNPRINTF (message, sizeof(message), "for %s %s in %s",
SPEC_USIGN(ltype) ? "unsigned" : "signed",
nounName(ltype), msg);
werror (W_CONST_RANGE, message);
SPEC_USIGN(ltype) ? "unsigned" : "signed",
nounName(ltype), msg);
werror (W_CONST_RANGE, message);
- sprintf (buffer, "%s", s);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "%s", s);
+ }
- sprintf (buffer, "iTemp%d", iTempNum++);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "iTemp%d", iTempNum++);
+ }
+
itmp = newSymbol (buffer, 1);
strncpyz (itmp->rname, itmp->name, SDCC_NAME_MAX);
itmp->isitmp = 1;
itmp = newSymbol (buffer, 1);
strncpyz (itmp->rname, itmp->name, SDCC_NAME_MAX);
itmp->isitmp = 1;
- itmplbl = newSymbol (s, 1);
+ {
+ itmplbl = newSymbol (s, 1);
+ }
- sprintf (buffer, "iTempLbl%d", iTempLblNum++);
+ SNPRINTF (buffer, sizeof(buffer), "iTempLbl%d", iTempLblNum++);
itmplbl = newSymbol (buffer, 1);
}
itmplbl = newSymbol (buffer, 1);
}
- sprintf (buffer, "preHeaderLbl%d", iTempLblNum++);
+ SNPRINTF (buffer, sizeof(buffer), "preHeaderLbl%d", iTempLblNum++);
itmplbl = newSymbol (buffer, 1);
itmplbl->isitmp = 1;
itmplbl = newSymbol (buffer, 1);
itmplbl->isitmp = 1;
/* all integer numbers between the maximum & minimum must */
/* be present , the maximum value should not exceed 255 */
min = max = (int) floatFromVal (vch = caseVals);
/* all integer numbers between the maximum & minimum must */
/* be present , the maximum value should not exceed 255 */
min = max = (int) floatFromVal (vch = caseVals);
- sprintf (buffer, "_case_%d_%d",
+ SNPRINTF (buffer, sizeof(buffer),
+ "_case_%d_%d",
tree->values.switchVals.swNum,
min);
addSet (&labels, newiTempLabel (buffer));
tree->values.switchVals.swNum,
min);
addSet (&labels, newiTempLabel (buffer));
{
if (((t = (int) floatFromVal (vch)) - max) != 1)
return 0;
{
if (((t = (int) floatFromVal (vch)) - max) != 1)
return 0;
- sprintf (buffer, "_case_%d_%d",
+ SNPRINTF (buffer, sizeof(buffer),
+ "_case_%d_%d",
tree->values.switchVals.swNum,
t);
addSet (&labels, newiTempLabel (buffer));
tree->values.switchVals.swNum,
t);
addSet (&labels, newiTempLabel (buffer));
return 0;
if (tree->values.switchVals.swDefault)
return 0;
if (tree->values.switchVals.swDefault)
- sprintf (buffer, "_default_%d", tree->values.switchVals.swNum);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "_default_%d", tree->values.switchVals.swNum);
+ }
- sprintf (buffer, "_swBrk_%d", tree->values.switchVals.swNum);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "_swBrk_%d", tree->values.switchVals.swNum);
+ }
+
falseLabel = newiTempLabel (buffer);
falseLabel = newiTempLabel (buffer);
operandFromValue (caseVals),
EQ_OP);
operandFromValue (caseVals),
EQ_OP);
- sprintf (buffer, "_case_%d_%d",
+ SNPRINTF (buffer, sizeof(buffer), "_case_%d_%d",
tree->values.switchVals.swNum,
(int) floatFromVal (caseVals));
trueLabel = newiTempLabel (buffer);
tree->values.switchVals.swNum,
(int) floatFromVal (caseVals));
trueLabel = newiTempLabel (buffer);
/* if default is present then goto break else break */
if (tree->values.switchVals.swDefault)
/* if default is present then goto break else break */
if (tree->values.switchVals.swDefault)
- sprintf (buffer, "_default_%d", tree->values.switchVals.swNum);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "_default_%d", tree->values.switchVals.swNum);
+ }
- sprintf (buffer, "_swBrk_%d", tree->values.switchVals.swNum);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "_swBrk_%d", tree->values.switchVals.swNum);
+ }
falseLabel = newiTempLabel (buffer);
geniCodeGoto (falseLabel);
falseLabel = newiTempLabel (buffer);
geniCodeGoto (falseLabel);
/* Recursivly evaluate all the macros in the string */
_evalMacros(ainto, pvals, pformat, MAX_STRING_LENGTH);
/* Evaluate all the arguments */
/* Recursivly evaluate all the macros in the string */
_evalMacros(ainto, pvals, pformat, MAX_STRING_LENGTH);
/* Evaluate all the arguments */
- vsprintf(atmp, ainto, ap);
+#if defined(HAVE_VSNPRINTF)
+ if (vsnprintf(atmp, MAX_STRING_LENGTH, ainto, ap) >= MAX_STRING_LENGTH)
+ {
+ fprintf(stderr, "Internal error: mvsprintf output truncated.\n");
+ }
+#else
+ {
+ int wlen;
+
+ wlen = vsprintf(atmp, ainto, ap);
+
+ if (wlen < 0 || wlen >= MAX_STRING_LENGTH)
+ {
+ wassertl(0, "mvsprintf overflowed.");
+ }
+ }
+#endif
+
/* Recursivly evaluate any macros that were used as arguments */
_evalMacros(ainto, pvals, atmp, MAX_STRING_LENGTH);
/* Recursivly evaluate any macros that were used as arguments */
_evalMacros(ainto, pvals, atmp, MAX_STRING_LENGTH);
(longOpt && unsupportedOptTable[i].longOpt && !strcmp(unsupportedOptTable[i].longOpt, longOpt))) {
// Found an unsupported opt.
char buffer[100];
(longOpt && unsupportedOptTable[i].longOpt && !strcmp(unsupportedOptTable[i].longOpt, longOpt))) {
// Found an unsupported opt.
char buffer[100];
- sprintf(buffer, "%s%c%c", longOpt ? longOpt : "", shortOpt ? '-' : ' ', shortOpt ? shortOpt : ' ');
+ SNPRINTF(buffer, sizeof(buffer),
+ "%s%c%c",
+ longOpt ? longOpt : "",
+ shortOpt ? '-' : ' ', shortOpt ? shortOpt : ' ');
werror (W_UNSUPP_OPTION, buffer, unsupportedOptTable[i].message);
return 1;
}
werror (W_UNSUPP_OPTION, buffer, unsupportedOptTable[i].message);
return 1;
}
if (sOpt == 'Y')
sOpt = 'I';
if (sOpt == 'Y')
sOpt = 'I';
- sprintf (buffer, "-%c%s", sOpt, rest);
+ SNPRINTF (buffer, sizeof(buffer), "-%c%s", sOpt, rest);
addToList (preArgv, buffer);
}
break;
addToList (preArgv, buffer);
}
break;
/* if debug option is set the open the cdbFile */
if (options.debug && fullSrcFileName)
{
/* if debug option is set the open the cdbFile */
if (options.debug && fullSrcFileName)
{
- sprintf (scratchFileName, "%s.adb", dstFileName); //JCF: Nov 30, 2002
+ SNPRINTF (scratchFileName, sizeof(scratchFileName),
+ "%s.adb", dstFileName); //JCF: Nov 30, 2002
if ((cdbFile = fopen (scratchFileName, "w")) == NULL)
werror (E_FILE_OPEN_ERR, scratchFileName);
else
if ((cdbFile = fopen (scratchFileName, "w")) == NULL)
werror (E_FILE_OPEN_ERR, scratchFileName);
else
int i, system_ret;
/* first we need to create the <filename>.lnk file */
int i, system_ret;
/* first we need to create the <filename>.lnk file */
- sprintf (scratchFileName, "%s.lnk", dstFileName);
+ SNPRINTF (scratchFileName, sizeof(scratchFileName),
+ "%s.lnk", dstFileName);
if (!(lnkfile = fopen (scratchFileName, "w")))
{
werror (E_FILE_OPEN_ERR, scratchFileName);
if (!(lnkfile = fopen (scratchFileName, "w")))
{
werror (E_FILE_OPEN_ERR, scratchFileName);
/* -o option overrides default name? */
if (fullDstFileName)
{
/* -o option overrides default name? */
if (fullDstFileName)
{
- strncpyz (scratchFileName, fullDstFileName, PATH_MAX);
+ strncpyz (scratchFileName, fullDstFileName, sizeof(scratchFileName));
}
else
{
/* the linked file gets the name of the first modul */
if (fullSrcFileName)
{
}
else
{
/* the linked file gets the name of the first modul */
if (fullSrcFileName)
{
- strncpyz (scratchFileName, dstFileName, PATH_MAX);
+ strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
- strncpyz (scratchFileName, relFiles[0], PATH_MAX);
+ strncpyz (scratchFileName, relFiles[0], sizeof(scratchFileName));
/* strip ".rel" extension */
*strrchr (scratchFileName, '.') = '\0';
}
/* strip ".rel" extension */
*strrchr (scratchFileName, '.') = '\0';
}
- strncatz (scratchFileName, options.out_fmt ? ".S19" : ".ihx", PATH_MAX);
+ strncatz (scratchFileName,
+ options.out_fmt ? ".S19" : ".ihx",
+ sizeof(scratchFileName));
/* the linked file gets the name of the first modul */
if (fullSrcFileName)
{
/* the linked file gets the name of the first modul */
if (fullSrcFileName)
{
- strncpyz (scratchFileName, dstFileName, PATH_MAX);
+ strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
p = strlen (scratchFileName) + scratchFileName;
}
else
{
p = strlen (scratchFileName) + scratchFileName;
}
else
{
- strncpyz (scratchFileName, relFiles[0], PATH_MAX);
+ strncpyz (scratchFileName, relFiles[0], sizeof(scratchFileName));
/* strip "rel" extension */
p = strrchr (scratchFileName, '.');
if (p)
/* strip "rel" extension */
p = strrchr (scratchFileName, '.');
if (p)
- strncatz (scratchFileName, options.out_fmt ? "S19" : "ihx", PATH_MAX);
+ strncatz (scratchFileName,
+ options.out_fmt ? "S19" : "ihx",
+ sizeof(scratchFileName));
rename (scratchFileName, fullDstFileName);
q = strrchr (fullDstFileName, '.');
rename (scratchFileName, fullDstFileName);
q = strrchr (fullDstFileName, '.');
- strncatz (scratchFileName, "map", PATH_MAX);
+ strncatz (scratchFileName, "map", sizeof(scratchFileName));
- strncatz(fullDstFileName, "map", PATH_MAX);
+ strncatz(fullDstFileName, "map", fullDstFileNameLen);
rename (scratchFileName, fullDstFileName);
*p = 0;
rename (scratchFileName, fullDstFileName);
*p = 0;
- strncatz (scratchFileName, "mem", PATH_MAX);
+ strncatz (scratchFileName, "mem", sizeof(scratchFileName));
- strncatz(fullDstFileName, "mem", PATH_MAX);
+ strncatz(fullDstFileName, "mem", fullDstFileNameLen);
rename (scratchFileName, fullDstFileName);
}
if (system_ret)
rename (scratchFileName, fullDstFileName);
}
if (system_ret)
/* -o option overrides default name? */
if (options.cc_only && fullDstFileName) {
/* -o option overrides default name? */
if (options.cc_only && fullDstFileName) {
- strncpyz (scratchFileName, fullDstFileName, PATH_MAX);
+ strncpyz (scratchFileName, fullDstFileName, sizeof(scratchFileName));
} else {
/* the assembled file gets the name of the first modul */
strncpyz (scratchFileName, dstFileName, PATH_MAX);
} else {
/* the assembled file gets the name of the first modul */
strncpyz (scratchFileName, dstFileName, PATH_MAX);
options.debug ? port->assembler.debug_opts : port->assembler.plain_opts,
asmOptions);
} else {
options.debug ? port->assembler.debug_opts : port->assembler.plain_opts,
asmOptions);
} else {
- buildCmdLine2 (buffer, port->assembler.mcmd, PATH_MAX);
+ buildCmdLine2 (buffer, port->assembler.mcmd, sizeof(buffer));
}
if (my_system (buffer)) {
}
if (my_system (buffer)) {
/* TODO: most assembler don't have a -o parameter */
/* -o option overrides default name? */
if (options.cc_only && fullDstFileName) {
/* TODO: most assembler don't have a -o parameter */
/* -o option overrides default name? */
if (options.cc_only && fullDstFileName) {
- strncpyz (scratchFileName, dstFileName, PATH_MAX);
- strncatz (scratchFileName, port->linker.rel_ext, PATH_MAX);
+ strncpyz (scratchFileName, dstFileName, sizeof(scratchFileName));
+ strncatz (scratchFileName,
+ port->linker.rel_ext,
+ sizeof(scratchFileName));
rename (scratchFileName, fullDstFileName);
}
}
rename (scratchFileName, fullDstFileName);
}
}
where expected. If so, set.
*/
getPathDifference (buffer, PREFIX, SDCC_INCLUDE_DIR);
where expected. If so, set.
*/
getPathDifference (buffer, PREFIX, SDCC_INCLUDE_DIR);
- strncpyz (scratchFileName, pprefix, PATH_MAX);
- strncatz (scratchFileName, buffer, PATH_MAX);
+ strncpyz (scratchFileName, pprefix, sizeof(scratchFileName));
+ strncatz (scratchFileName, buffer, sizeof(scratchFileName));
if (pathExists (scratchFileName))
{
if (pathExists (scratchFileName))
{
}
getPathDifference (buffer, PREFIX, SDCC_LIB_DIR);
}
getPathDifference (buffer, PREFIX, SDCC_LIB_DIR);
- strncpyz (scratchFileName, pprefix, PATH_MAX);
- strncatz (scratchFileName, buffer, PATH_MAX);
+ strncpyz (scratchFileName, pprefix, sizeof(scratchFileName));
+ strncatz (scratchFileName, buffer, sizeof(scratchFileName));
if (pathExists (scratchFileName))
{
if (pathExists (scratchFileName))
{
*/
if (strchr (argv0, DIR_SEPARATOR_CHAR))
{
*/
if (strchr (argv0, DIR_SEPARATOR_CHAR))
{
- strncpyz (scratchFileName, argv0, PATH_MAX);
+ strncpyz (scratchFileName, argv0, sizeof(scratchFileName));
*strrchr (scratchFileName, DIR_SEPARATOR_CHAR) = '\0';
setMainValue ("bindir", scratchFileName);
ExePathList[0] = Safe_strdup (scratchFileName);
*strrchr (scratchFileName, DIR_SEPARATOR_CHAR) = '\0';
setMainValue ("bindir", scratchFileName);
ExePathList[0] = Safe_strdup (scratchFileName);
else if (getenv (SDCCDIR_NAME) != NULL)
{
getPathDifference (buffer, PREFIX, BINDIR);
else if (getenv (SDCCDIR_NAME) != NULL)
{
getPathDifference (buffer, PREFIX, BINDIR);
- strncpyz (scratchFileName, getenv (SDCCDIR_NAME), PATH_MAX);
+ strncpyz (scratchFileName, getenv (SDCCDIR_NAME), sizeof(scratchFileName));
strncatz (scratchFileName, buffer, PATH_MAX);
setMainValue ("bindir", scratchFileName);
ExePathList[0] = Safe_strdup (scratchFileName);
strncatz (scratchFileName, buffer, PATH_MAX);
setMainValue ("bindir", scratchFileName);
ExePathList[0] = Safe_strdup (scratchFileName);
/* symbol name is internal name */
if (!sym->level) /* local statics can come here */
/* symbol name is internal name */
if (!sym->level) /* local statics can come here */
- sprintf (sym->rname, "%s%s", port->fun_prefix, sym->name);
+ SNPRINTF (sym->rname, sizeof(sym->rname),
+ "%s%s", port->fun_prefix, sym->name);
/* add it to the operandKey reset */
addSet (&operKeyReset, sym);
/* add it to the operandKey reset */
addSet (&operKeyReset, sym);
else
{ /* allocate them in the automatic space */
/* generate a unique name */
else
{ /* allocate them in the automatic space */
/* generate a unique name */
- sprintf (lval->sym->rname, "%s%s_PARM_%d", port->fun_prefix, currFunc->name, pNum);
+ SNPRINTF (lval->sym->rname, sizeof(lval->sym->rname),
+ "%s%s_PARM_%d", port->fun_prefix, currFunc->name, pNum);
strncpyz (lval->name, lval->sym->rname, sizeof(lval->name));
/* if declared in external storage */
strncpyz (lval->name, lval->sym->rname, sizeof(lval->name));
/* if declared in external storage */
{
/* generate an unique name */
{
/* generate an unique name */
- sprintf (sym->rname, "%s%s_%s_%d_%d",
- port->fun_prefix,
- currFunc->name, sym->name, sym->level, sym->block);
+ SNPRINTF (sym->rname, sizeof(sym->rname),
+ "%s%s_%s_%d_%d",
+ port->fun_prefix,
+ currFunc->name, sym->name, sym->level, sym->block);
sym->islocal = 1;
sym->localof = currFunc;
sym->islocal = 1;
sym->localof = currFunc;
char buff[MAX_PATTERN_LEN];
int dist = 0;
char buff[MAX_PATTERN_LEN];
int dist = 0;
- sprintf (buff, "%s:", lbl);
+ SNPRINTF (buff, sizeof(buff), "%s:", lbl);
*s = vvx;
*vv = '\0';
/* got value */
*s = vvx;
*vv = '\0';
/* got value */
- vvx = traceAlloc (&_G.values, Safe_alloc(strlen (vval) + 1));
- strcpy (vvx, vval);
+ vvx = traceAlloc (&_G.values, Safe_strdup(vval));
hTabAddItem (vtab, key, vvx);
}
hTabAddItem (vtab, key, vvx);
}
if (rs)
{
rs = Safe_realloc (rs, strlen (rs) + strlen (lb) + 1);
if (rs)
{
rs = Safe_realloc (rs, strlen (rs) + strlen (lb) + 1);
+ strncatz (rs, lb, strlen (rs) + strlen (lb) + 1);
if (rs)
{
rs = Safe_realloc (rs, strlen (rs) + strlen (lb) + 1);
if (rs)
{
rs = Safe_realloc (rs, strlen (rs) + strlen (lb) + 1);
+ strncatz (rs, lb, strlen (rs) + strlen (lb) + 1);
bp->sym = sym; /* update the symbol pointer */
bp->level = level; /* update the nest level */
bp->block = block;
bp->sym = sym; /* update the symbol pointer */
bp->level = level; /* update the nest level */
bp->block = block;
- strcpy (bp->name, sname); /* copy the name into place */
+ strncpyz (bp->name, sname, sizeof(bp->name)); /* copy the name into place */
/* if this is the first entry */
if (stab[i] == NULL)
/* if this is the first entry */
if (stab[i] == NULL)
sym = Safe_alloc ( sizeof (symbol));
sym = Safe_alloc ( sizeof (symbol));
- strcpy (sym->name, name); /* copy the name */
+ strncpyz (sym->name, name, sizeof(sym->name)); /* copy the name */
sym->level = scope; /* set the level */
sym->block = currBlockno;
sym->lineDef = yylineno; /* set the line number */
sym->level = scope; /* set the level */
sym->block = currBlockno;
sym->lineDef = yylineno; /* set the line number */
s = Safe_alloc ( sizeof (structdef));
s = Safe_alloc ( sizeof (structdef));
- strcpy (s->tag, tag); /* copy the tag */
+ strncpyz (s->tag, tag, sizeof(s->tag)); /* copy the tag */
static int gCount = 0;
static char gname[SDCC_NAME_MAX + 1];
static int gCount = 0;
static char gname[SDCC_NAME_MAX + 1];
- sprintf (gname, "__%04d%04d", level, gCount++);
+ SNPRINTF (gname, sizeof(gname), "__%04d%04d", level, gCount++);
while (loop) {
/* create the internal name for this variable */
while (loop) {
/* create the internal name for this variable */
- sprintf (loop->rname, "_%s", loop->name);
+ SNPRINTF (loop->rname, sizeof(loop->rname), "_%s", loop->name);
loop->offset = (su == UNION ? sum = 0 : sum);
SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
loop->offset = (su == UNION ? sum = 0 : sum);
SPEC_VOLATILE (loop->etype) |= (su == UNION ? 1 : 0);
// this can happen for reentrant functions
werror(E_PARAM_NAME_OMITTED, sym->name, argCnt);
// the show must go on: synthesize a name and symbol
// this can happen for reentrant functions
werror(E_PARAM_NAME_OMITTED, sym->name, argCnt);
// the show must go on: synthesize a name and symbol
- sprintf (acargs->name, "_%s_PARM_%d", sym->name, argCnt);
+ SNPRINTF (acargs->name, sizeof(acargs->name), "_%s_PARM_%d", sym->name, argCnt);
acargs->sym = newSymbol (acargs->name, 1);
SPEC_OCLS (acargs->etype) = istack;
acargs->sym->type = copyLinkChain (acargs->type);
acargs->sym->etype = getSpec (acargs->sym->type);
acargs->sym->_isparm = 1;
acargs->sym = newSymbol (acargs->name, 1);
SPEC_OCLS (acargs->etype) = istack;
acargs->sym->type = copyLinkChain (acargs->type);
acargs->sym->etype = getSpec (acargs->sym->type);
acargs->sym->_isparm = 1;
- strcpy (acargs->sym->rname, acargs->name);
+ strncpyz (acargs->sym->rname, acargs->name, sizeof(acargs->sym->rname));
} else if (strcmp(acargs->sym->name, acargs->sym->rname)==0) {
// synthesized name
werror(E_PARAM_NAME_OMITTED, sym->name, argCnt);
} else if (strcmp(acargs->sym->name, acargs->sym->rname)==0) {
// synthesized name
werror(E_PARAM_NAME_OMITTED, sym->name, argCnt);
/* synthesize a variable name */
if (!val->sym)
{
/* synthesize a variable name */
if (!val->sym)
{
- sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
+ SNPRINTF (val->name, sizeof(val->name),
+ "_%s_PARM_%d", func->name, pNum++);
val->sym = newSymbol (val->name, 1);
SPEC_OCLS (val->etype) = port->mem.default_local_map;
val->sym->type = copyLinkChain (val->type);
val->sym->etype = getSpec (val->sym->type);
val->sym->_isparm = 1;
val->sym = newSymbol (val->name, 1);
SPEC_OCLS (val->etype) = port->mem.default_local_map;
val->sym->type = copyLinkChain (val->type);
val->sym->etype = getSpec (val->sym->type);
val->sym->_isparm = 1;
- strcpy (val->sym->rname, val->name);
+ strncpyz (val->sym->rname, val->name, sizeof(val->sym->rname));
SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
SPEC_STAT (func->etype);
addSymChain (val->sym);
SPEC_STAT (val->etype) = SPEC_STAT (val->sym->etype) =
SPEC_STAT (func->etype);
addSymChain (val->sym);
else /* symbol name given create synth name */
{
else /* symbol name given create synth name */
{
- sprintf (val->name, "_%s_PARM_%d", func->name, pNum++);
- strcpy (val->sym->rname, val->name);
+ SNPRINTF (val->name, sizeof(val->name), "_%s_PARM_%d", func->name, pNum++);
+ strncpyz (val->sym->rname, val->name, sizeof(val->sym->rname));
val->sym->_isparm = 1;
SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
(options.model != MODEL_SMALL ? xdata : data);
val->sym->_isparm = 1;
SPEC_OCLS (val->etype) = SPEC_OCLS (val->sym->etype) =
(options.model != MODEL_SMALL ? xdata : data);
- sprintf (buffer, "__fs2%s%s", ssu[su], sbwd[bwd]);
+ SNPRINTF (buffer, sizeof(buffer), "__fs2%s%s", ssu[su], sbwd[bwd]);
__conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
}
else
{
__conv[tofrom][bwd][su] = funcOfType (buffer, __multypes[bwd][su], floatType, 1, options.float_rent);
}
else
{
- sprintf (buffer, "__%s%s2fs", ssu[su], sbwd[bwd]);
+ SNPRINTF (buffer, sizeof(buffer), "__%s%s2fs", ssu[su], sbwd[bwd]);
__conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
}
}
__conv[tofrom][bwd][su] = funcOfType (buffer, floatType, __multypes[bwd][su], 1, options.float_rent);
}
}
{
for (su = 0; su < 2; su++)
{
{
for (su = 0; su < 2; su++)
{
- sprintf (buffer, "_%s%s%s",
+ SNPRINTF (buffer, sizeof(buffer),
+ "_%s%s%s",
smuldivmod[muldivmod],
ssu[su],
sbwd[bwd]);
smuldivmod[muldivmod],
ssu[su],
sbwd[bwd]);
{
for (su = 0; su < 2; su++)
{
{
for (su = 0; su < 2; su++)
{
- sprintf (buffer, "_%s%s%s",
+ SNPRINTF (buffer, sizeof(buffer),
+ "_%s%s%s",
srlrr[rlrr],
ssu[su],
sbwd[bwd]);
srlrr[rlrr],
ssu[su],
sbwd[bwd]);
{
fprintf(stderr, "internal error: sprintf truncated.\n");
}
{
fprintf(stderr, "internal error: sprintf truncated.\n");
}
- sprintf (val->name, "%s", sym->rname);
+ {
+ SNPRINTF (val->name, sizeof(val->name), "%s", sym->rname);
+ }
- sprintf (val->name, "_%s", sym->name);
-
+ {
+ SNPRINTF (val->name, sizeof(val->name), "_%s", sym->name);
+ }
if ((((long) lit) - lit) == 0)
{
if ((((long) lit) - lit) == 0)
{
- sprintf (buffer, "%ld", (long) lit);
+ SNPRINTF (buffer, sizeof(buffer), "%ld", (long) lit);
return constVal (buffer);
}
return constVal (buffer);
}
- sprintf (buffer, "%f", lit);
+ SNPRINTF (buffer, sizeof(buffer), "%f", lit);
return constFloatVal (buffer);
}
return constFloatVal (buffer);
}
val = newValue ();
if (!lval)
val = newValue ();
if (!lval)
- sprintf (buffer, "%s", AST_SYMBOL (arrExpr->left)->rname);
+ {
+ SNPRINTF (buffer, sizeof(buffer), "%s", AST_SYMBOL (arrExpr->left)->rname);
+ }
- 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 ();
(int) AST_LIT_VALUE (arrExpr->right) * size);
val->type = newLink ();
val = newValue ();
if (!lval)
val = newValue ();
if (!lval)
- sprintf (buffer, "%s", AST_SYMBOL (structT)->rname);
+ {
+ SNPRINTF(buffer, sizeof(buffer), "%s", AST_SYMBOL (structT)->rname);
+ }
- 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 ();
(int) sym->offset);
val->type = newLink ();
- 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));
AST_SYMBOL (aexpr)->rname, op,
getSize (type->next) * (int) AST_LIT_VALUE (cnst));
- sprintf (val->name, "(%s)",
+ SNPRINTF (val->name, sizeof(val->name), "(%s)",
AST_SYMBOL (aexpr)->rname);
val->type = type;
AST_SYMBOL (aexpr)->rname);
val->type = type;
/* check if it is in the typedef table */
if (findSym (TypedefTab, NULL, sz))
{
/* check if it is in the typedef table */
if (findSym (TypedefTab, NULL, sz))
{
- strcpy (yylval.yychar, sz);
+ strncpyz (yylval.yychar, sz, sizeof(yylval.yychar));
return TYPE_NAME;
}
else
{
return TYPE_NAME;
}
else
{
- strcpy (yylval.yychar, sz);
+ strncpyz (yylval.yychar, sz, sizeof(yylval.yychar));
altlex_testparse (const char *input)
{
/* Fiddle with the read-ahead buffer to insert ourselves */
altlex_testparse (const char *input)
{
/* Fiddle with the read-ahead buffer to insert ourselves */
- strcpy (linebuf, input);
+ strncpyz (linebuf, input, sizeof(linebuf));
linelen = strlen (linebuf) + 1;
linepos = 0;
linelen = strlen (linebuf) + 1;
linepos = 0;
we need to allocate this on the stack : this is really a
hack!! but cannot think of anything better at this time */
we need to allocate this on the stack : this is really a
hack!! but cannot think of anything better at this time */
- if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
+ if (SNPRINTF (slocBuffer, sizeof(slocBuffer),
+ "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
{
fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
__FILE__, __LINE__);
{
fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
__FILE__, __LINE__);
if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
{
sym = leastUsedLR (selectS);
if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
{
sym = leastUsedLR (selectS);
- strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
- sym->usl.spillLoc->rname :
- sym->usl.spillLoc->name));
+ strncpyz (sym->rname,
+ sym->usl.spillLoc->rname[0] ?
+ sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
+ sizeof(sym->rname));
sym->spildir = 1;
/* mark it as allocation required */
sym->usl.spillLoc->allocreq++;
sym->spildir = 1;
/* mark it as allocation required */
sym->usl.spillLoc->allocreq++;
char *s = buffer;
iCode *ic = sym->rematiCode;
char *s = buffer;
iCode *ic = sym->rematiCode;
while (1)
{
/* if plus or minus print the right hand side */
if (ic->op == '+' || ic->op == '-')
{
while (1)
{
/* if plus or minus print the right hand side */
if (ic->op == '+' || ic->op == '-')
{
- sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
- ic->op);
+ SNPRINTF (s, sizeof(buffer) - strlen(buffer),
+ "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
+ ic->op);
s += strlen (s);
ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
continue;
s += strlen (s);
ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
continue;
continue;
}
/* we reached the end */
continue;
}
/* we reached the end */
- sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ SNPRINTF (s, sizeof(buffer) - strlen(buffer),
+ "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
psym->type = sym->type;
psym->etype = sym->etype;
symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
psym->type = sym->type;
psym->etype = sym->etype;
- strcpy (psym->rname, psym->name);
+ strncpyz (psym->rname, psym->name, sizeof(psym->rname));
sym->isspilt = 1;
sym->usl.spillLoc = psym;
continue;
sym->isspilt = 1;
sym->usl.spillLoc = psym;
continue;