Commit ddb6e8e3 by kbr@chromium.org

Stop using unsafe sprintf method.

ISSUE=308 Signed-off-by: Kenneth Russell Author: David Kilzer git-svn-id: https://angleproject.googlecode.com/svn/trunk@1052 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 28182485
......@@ -20,7 +20,7 @@ namespace sh
TString str(int i)
{
char buffer[20];
sprintf(buffer, "%d", i);
snprintf(buffer, sizeof(buffer), "%d", i);
return buffer;
}
......
......@@ -158,10 +158,10 @@ void TAllocation::checkGuardBlock(unsigned char* blockMem, unsigned char val, co
// We don't print the assert message. It's here just to be helpful.
#if defined(_MSC_VER)
sprintf(assertMsg, "PoolAlloc: Damage %s %Iu byte allocation at 0x%p\n",
snprintf(assertMsg, sizeof(assertMsg), "PoolAlloc: Damage %s %Iu byte allocation at 0x%p\n",
locText, size, data());
#else
sprintf(assertMsg, "PoolAlloc: Damage %s %zu byte allocation at 0x%p\n",
snprintf(assertMsg, sizeof(assertMsg), "PoolAlloc: Damage %s %zu byte allocation at 0x%p\n",
locText, size, data());
#endif
assert(0 && "PoolAlloc: Damage in guard block");
......
......@@ -56,7 +56,7 @@ void TType::buildMangledName(TString& mangledName)
mangledName += static_cast<char>('0' + getNominalSize());
if (isArray()) {
char buf[20];
sprintf(buf, "%d", arraySize);
snprintf(buf, sizeof(buf), "%d", arraySize);
mangledName += '[';
mangledName += buf;
mangledName += ']';
......
......@@ -434,14 +434,14 @@ static int FindHashLoc(AtomTable *atable, const char *s)
if (cpp->options.DumpAtomTable) {
int ii;
char str[200];
sprintf(str, "*** Hash failed with more than %d collisions. Must increase hash table size. ***",
snprintf(str, sizeof(str), "*** Hash failed with more than %d collisions. Must increase hash table size. ***",
HASH_TABLE_MAX_COLLISIONS);
CPPShInfoLogMsg(str);
sprintf(str, "*** New string \"%s\", hash=%04x, delta=%04x", s, collision[0], hashdelta);
snprintf(str, sizeof(str), "*** New string \"%s\", hash=%04x, delta=%04x", s, collision[0], hashdelta);
CPPShInfoLogMsg(str);
for (ii = 0; ii <= HASH_TABLE_MAX_COLLISIONS; ii++) {
sprintf(str, "*** Collides on try %d at hash entry %04x with \"%s\"",
snprintf(str, sizeof(str), "*** Collides on try %d at hash entry %04x with \"%s\"",
ii + 1, collision[ii], GetAtomString(atable, atable->htable.entry[collision[ii]].value));
CPPShInfoLogMsg(str);
}
......@@ -685,14 +685,14 @@ void PrintAtomTable(AtomTable *atable)
char str[200];
for (ii = 0; ii < atable->nextFree; ii++) {
sprintf(str, "%d: \"%s\"", ii, &atable->stable.strings[atable->amap[ii]]);
snprintf(str, sizeof(str), "%d: \"%s\"", ii, &atable->stable.strings[atable->amap[ii]]);
CPPDebugLogMsg(str);
}
sprintf(str, "Hash table: size=%d, entries=%d, collisions=",
snprintf(str, sizeof(str), "Hash table: size=%d, entries=%d, collisions=",
atable->htable.size, atable->htable.entries);
CPPDebugLogMsg(str);
for (ii = 0; ii < HASH_TABLE_MAX_COLLISIONS; ii++) {
sprintf(str, " %d", atable->htable.counts[ii]);
snprintf(str, sizeof(str), " %d", atable->htable.counts[ii]);
CPPDebugLogMsg(str);
}
......
......@@ -892,7 +892,7 @@ void PredefineIntMacro(const char *name, int value) {
macro.body = NewTokenStream(name, macros->pool);
val.sc_int = value;
sprintf(val.symbol_name, "%d", value);
snprintf(val.symbol_name, MAX_SYMBOL_NAME_LEN+1, "%d", value);
RecordToken(macro.body, CPP_INTCONSTANT, &val);
atom = LookUpAddString(atable, name);
symbol = AddSymbol(&location, macros, atom, MACRO_S);
......@@ -989,13 +989,13 @@ int MacroExpand(int atom, yystypepp * yylvalpp)
const char *message;
if (atom == __LINE__Atom) {
yylvalpp->sc_int = GetLineNumber();
sprintf(yylvalpp->symbol_name,"%d",yylvalpp->sc_int);
snprintf(yylvalpp->symbol_name, MAX_SYMBOL_NAME_LEN+1, "%d", yylvalpp->sc_int);
UngetToken(CPP_INTCONSTANT, yylvalpp);
return 1;
}
if (atom == __FILE__Atom) {
yylvalpp->sc_int = GetStringNumber();
sprintf(yylvalpp->symbol_name,"%d",yylvalpp->sc_int);
snprintf(yylvalpp->symbol_name, MAX_SYMBOL_NAME_LEN+1, "%d", yylvalpp->sc_int);
UngetToken(CPP_INTCONSTANT, yylvalpp);
return 1;
}
......
......@@ -439,10 +439,10 @@ void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) {
switch (token) {
case CPP_IDENTIFIER:
case CPP_TYPEIDENTIFIER:
sprintf(str, "%s ", GetAtomString(atable, yylvalpp->sc_ident));
snprintf(str, sizeof(str), "%s ", GetAtomString(atable, yylvalpp->sc_ident));
break;
case CPP_STRCONSTANT:
sprintf(str, "\"%s\"", GetAtomString(atable, yylvalpp->sc_ident));
snprintf(str, sizeof(str), "\"%s\"", GetAtomString(atable, yylvalpp->sc_ident));
break;
case CPP_FLOATCONSTANT:
//printf("%g9.6 ", yylvalpp->sc_fval);
......@@ -452,9 +452,9 @@ void DumpTokenStream(FILE *fp, TokenStream *s, yystypepp * yylvalpp) {
break;
default:
if (token >= 127)
sprintf(str, "%s ", GetAtomString(atable, token));
snprintf(str, sizeof(str), "%s ", GetAtomString(atable, token));
else
sprintf(str, "%c", token);
snprintf(str, sizeof(str), "%c", token);
break;
}
CPPDebugLogMsg(str);
......
......@@ -29,7 +29,7 @@ const char *fakepath = "C:\\fakepath";
std::string str(int i)
{
char buffer[20];
sprintf(buffer, "%d", i);
snprintf(buffer, sizeof(buffer), "%d", i);
return buffer;
}
......
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