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
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index 2492f0e..66d4b23 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -20,7 +20,7 @@
 TString str(int i)
 {
     char buffer[20];
-    sprintf(buffer, "%d", i);
+    snprintf(buffer, sizeof(buffer), "%d", i);
     return buffer;
 }
 
diff --git a/src/compiler/PoolAlloc.cpp b/src/compiler/PoolAlloc.cpp
index a600c02..a3bc23e 100644
--- a/src/compiler/PoolAlloc.cpp
+++ b/src/compiler/PoolAlloc.cpp
@@ -158,10 +158,10 @@
 
             // 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");
diff --git a/src/compiler/SymbolTable.cpp b/src/compiler/SymbolTable.cpp
index edbea99..01ec0db 100644
--- a/src/compiler/SymbolTable.cpp
+++ b/src/compiler/SymbolTable.cpp
@@ -56,7 +56,7 @@
     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 += ']';
diff --git a/src/compiler/preprocessor/atom.c b/src/compiler/preprocessor/atom.c
index a17c319..e79d80f 100644
--- a/src/compiler/preprocessor/atom.c
+++ b/src/compiler/preprocessor/atom.c
@@ -434,14 +434,14 @@
             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 @@
     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);
     }
 
diff --git a/src/compiler/preprocessor/cpp.c b/src/compiler/preprocessor/cpp.c
index 81c948d..1aa1652 100644
--- a/src/compiler/preprocessor/cpp.c
+++ b/src/compiler/preprocessor/cpp.c
@@ -892,7 +892,7 @@
 
     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 @@
     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;
     }
diff --git a/src/compiler/preprocessor/tokens.c b/src/compiler/preprocessor/tokens.c
index f358e50..fad518c 100644
--- a/src/compiler/preprocessor/tokens.c
+++ b/src/compiler/preprocessor/tokens.c
@@ -439,10 +439,10 @@
         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 @@
             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);
diff --git a/src/libGLESv2/Program.cpp b/src/libGLESv2/Program.cpp
index 581cb14..d55de82 100644
--- a/src/libGLESv2/Program.cpp
+++ b/src/libGLESv2/Program.cpp
@@ -29,7 +29,7 @@
 std::string str(int i)
 {
     char buffer[20];
-    sprintf(buffer, "%d", i);
+    snprintf(buffer, sizeof(buffer), "%d", i);
     return buffer;
 }