Pass format sizes to scanf string arguments in codesighs.c. (Bug 533647) r=bsmedberg
authorL. David Baron <dbaron@dbaron.org>
Mon, 21 Dec 2009 16:46:25 -0500
changeset 36524 833f5ebf46519109cc3168afe0e14851f05d6b9c
parent 36523 cfa10b01b1f657b7ac20ccaef5a666ffc334881c
child 36525 bfe4de8f0428de92bdd54c994b8fa321e05fb613
push id10857
push userdbaron@mozilla.com
push dateMon, 21 Dec 2009 21:46:59 +0000
treeherdermozilla-central@48175bb06cb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs533647
milestone1.9.3a1pre
Pass format sizes to scanf string arguments in codesighs.c. (Bug 533647) r=bsmedberg
tools/codesighs/codesighs.c
tools/codesighs/maptsvdifftool.c
tools/codesighs/msmap2tsv.c
--- a/tools/codesighs/codesighs.c
+++ b/tools/codesighs/codesighs.c
@@ -222,49 +222,59 @@ void trimWhite(char* inString)
         }
         else
         {
             break;
         }
     }
 }
 
-
 int codesighs(Options* inOptions)
 /*
 **  Output a simplistic report based on our options.
 */
 {
     int retval = 0;
     char lineBuffer[0x1000];
     int scanRes = 0;
     unsigned long size;
-    char segClass[0x10];
-    char scope[0x10];
-    char module[0x100];
-    char segment[0x40];
-    char object[0x100];
+    #define SEGCLASS_CHARS 15
+    char segClass[SEGCLASS_CHARS + 1];
+    #define SCOPE_CHARS 15
+    char scope[SCOPE_CHARS + 1];
+    #define MODULE_CHARS 255
+    char module[MODULE_CHARS + 1];
+    #define SEGMENT_CHARS 63
+    char segment[SEGMENT_CHARS + 1];
+    #define OBJECT_CHARS 255
+    char object[OBJECT_CHARS + 1];
     char* symbol;
     SizeStats overall;
     ModuleStats* modules = NULL;
     unsigned moduleCount = 0;
 
     memset(&overall, 0, sizeof(overall));
 
     /*
     **  Read the file line by line, regardless of number of fields.
     **  We assume tab separated value formatting, at least 7 lead values:
     **      size class scope module segment object symbol ....
     */
     while(0 == retval && NULL != fgets(lineBuffer, sizeof(lineBuffer), inOptions->mInput))
     {
         trimWhite(lineBuffer);
 
+#define STRINGIFY(s_) STRINGIFY2(s_)
+#define STRINGIFY2(s_) #s_
+
         scanRes = sscanf(lineBuffer,
-            "%x\t%s\t%s\t%s\t%s\t%s\t",
+            "%x\t%" STRINGIFY(SEGCLASS_CHARS) "s\t%"
+            STRINGIFY(SCOPE_CHARS) "s\t%" STRINGIFY(MODULE_CHARS)
+            "s\t%" STRINGIFY(SEGMENT_CHARS) "s\t%"
+            STRINGIFY(OBJECT_CHARS) "s\t",
             (unsigned*)&size,
             segClass,
             scope,
             module,
             segment,
             object);
 
         if(6 == scanRes)
--- a/tools/codesighs/maptsvdifftool.c
+++ b/tools/codesighs/maptsvdifftool.c
@@ -381,37 +381,49 @@ int difftool(Options* inOptions)
         trimWhite(lineBuffer);
 
         if(('<' == lineBuffer[0] || '>' == lineBuffer[0]) && ' ' == lineBuffer[1])
         {
             int additive = 0;
             char* theLine = &lineBuffer[2];
             int scanRes = 0;
             int size;
-            char segClass[0x10];
-            char scope[0x10];
-            char module[0x100];
-            char segment[0x40];
-            char object[0x100];
+            #define SEGCLASS_CHARS 15
+            char segClass[SEGCLASS_CHARS + 1];
+            #define SCOPE_CHARS 15
+            char scope[SCOPE_CHARS + 1];
+            #define MODULE_CHARS 255
+            char module[MODULE_CHARS + 1];
+            #define SEGMENT_CHARS 63
+            char segment[SEGMENT_CHARS + 1];
+            #define OBJECT_CHARS 255
+            char object[OBJECT_CHARS + 1];
             char* symbol = NULL;
 
             /*
             **  Figure out if the line adds or subtracts from something.
             */
             if('>' == lineBuffer[0])
             {
                 additive = __LINE__;
             }
 
 
             /*
             **  Scan the line for information.
             */
+
+#define STRINGIFY(s_) STRINGIFY2(s_)
+#define STRINGIFY2(s_) #s_
+
             scanRes = sscanf(theLine,
-                "%x\t%s\t%s\t%s\t%s\t%s\t",
+                "%x\t%" STRINGIFY(SEGCLASS_CHARS) "s\t%"
+                STRINGIFY(SCOPE_CHARS) "s\t%" STRINGIFY(MODULE_CHARS)
+                "s\t%" STRINGIFY(SEGMENT_CHARS) "s\t%"
+                STRINGIFY(OBJECT_CHARS) "s\t",
                 (unsigned*)&size,
                 segClass,
                 scope,
                 module,
                 segment,
                 object);
 
             if(6 == scanRes)
--- a/tools/codesighs/msmap2tsv.c
+++ b/tools/codesighs/msmap2tsv.c
@@ -63,16 +63,19 @@
 #define DEMANGLE_STATE_START 9
 #define DEMANGLE_STATE_STOP 10
 #define DEMANGLE_SAFE_CHAR(eval)  (isprint(eval) ? eval : ' ')
 
 #else
 #define F_DEMANGLE 0
 #endif /* WIN32 */
 
+#define STRINGIFY(s_) STRINGIFY2(s_)
+#define STRINGIFY2(s_) #s_
+#define SYMBOL_BUF_CHARS 511
 
 #define ERROR_REPORT(num, val, msg)   fprintf(stderr, "error(%d):\t\"%s\"\t%s\n", (num), (val), (msg));
 #define CLEANUP(ptr)    do { if(NULL != ptr) { free(ptr); ptr = NULL; } } while(0)
 
 
 typedef struct __struct_SymDB_Size
 /*
 **  The size of the symbol.
@@ -1191,26 +1194,26 @@ int readmap(Options* inOptions, MSMap_Mo
                                             }
                                         }
                                         
                                         if(0 == retval && inModule->mSymbolCapacity > inModule->mSymbolCount)
                                         {
                                             MSMap_Symbol* theSymbol = NULL;
                                             unsigned index = 0;
                                             int scanRes = 0;
-                                            char symbolBuf[0x200];
+                                            char symbolBuf[SYMBOL_BUF_CHARS + 1];
                                             
                                             index = inModule->mSymbolCount;
                                             inModule->mSymbolCount++;
                                             theSymbol = (inModule->mSymbols + index);
                                             
                                             memset(theSymbol, 0, sizeof(MSMap_Symbol));
                                             theSymbol->mScope = STATIC;
                                             
-                                            scanRes = sscanf(current, "%x:%x %s %x", (unsigned*)&(theSymbol->mPrefix), (unsigned*)&(theSymbol->mOffset), symbolBuf, (unsigned*)&(theSymbol->mRVABase));
+                                            scanRes = sscanf(current, "%x:%x %" STRINGIFY(SYMBOL_BUF_CHARS) "s %x", (unsigned*)&(theSymbol->mPrefix), (unsigned*)&(theSymbol->mOffset), symbolBuf, (unsigned*)&(theSymbol->mRVABase));
                                             if(4 == scanRes)
                                             {
                                                 theSymbol->mSymbol = symdup(symbolBuf);
 
                                                 if(0 == retval)
                                                 {
                                                     if(NULL != theSymbol->mSymbol)
                                                     {
@@ -1316,26 +1319,26 @@ int readmap(Options* inOptions, MSMap_Mo
                                         }
                                     }
                                     
                                     if(0 == retval && inModule->mSymbolCapacity > inModule->mSymbolCount)
                                     {
                                         MSMap_Symbol* theSymbol = NULL;
                                         unsigned index = 0;
                                         int scanRes = 0;
-                                        char symbolBuf[0x200];
+                                        char symbolBuf[SYMBOL_BUF_CHARS + 1];
                                         
                                         index = inModule->mSymbolCount;
                                         inModule->mSymbolCount++;
                                         theSymbol = (inModule->mSymbols + index);
                                         
                                         memset(theSymbol, 0, sizeof(MSMap_Symbol));
                                         theSymbol->mScope = PUBLIC;
                                         
-                                        scanRes = sscanf(current, "%x:%x %s %x", (unsigned*)&(theSymbol->mPrefix), (unsigned*)&(theSymbol->mOffset), symbolBuf, (unsigned *)&(theSymbol->mRVABase));
+                                        scanRes = sscanf(current, "%x:%x %" STRINGIFY(SYMBOL_BUF_CHARS) "s %x", (unsigned*)&(theSymbol->mPrefix), (unsigned*)&(theSymbol->mOffset), symbolBuf, (unsigned *)&(theSymbol->mRVABase));
                                         if(4 == scanRes)
                                         {
                                             theSymbol->mSymbol = symdup(symbolBuf);
 
                                             if(NULL != theSymbol->mSymbol)
                                             {
                                                 char *last = lastWord(current);
                                                 
@@ -1411,27 +1414,29 @@ int readmap(Options* inOptions, MSMap_Mo
                                         ERROR_REPORT(retval, inModule->mModule, "Unable to grow segments.");
                                     }
                                 }
                                 
                                 if(0 == retval && inModule->mSegmentCapacity > inModule->mSegmentCount)
                                 {
                                     MSMap_Segment* theSegment = NULL;
                                     unsigned index = 0;
-                                    char classBuf[0x10];
-                                    char nameBuf[0x20];
+                                    #define CLASS_BUF_CHARS 15
+                                    char classBuf[CLASS_BUF_CHARS + 1];
+                                    #define NAME_BUF_CHARS 31
+                                    char nameBuf[NAME_BUF_CHARS + 1];
                                     int scanRes = 0;
                                     
                                     index = inModule->mSegmentCount;
                                     inModule->mSegmentCount++;
                                     theSegment = (inModule->mSegments + index);
                                     
                                     memset(theSegment, 0, sizeof(MSMap_Segment));
                                     
-                                    scanRes = sscanf(current, "%x:%x %xH %s %s", (unsigned*)&(theSegment->mPrefix), (unsigned*)&(theSegment->mOffset), (unsigned*)&(theSegment->mLength), nameBuf, classBuf);
+                                    scanRes = sscanf(current, "%x:%x %xH %" STRINGIFY(NAME_BUF_CHARS) "s %" STRINGIFY(CLASS_BUF_CHARS) "s", (unsigned*)&(theSegment->mPrefix), (unsigned*)&(theSegment->mOffset), (unsigned*)&(theSegment->mLength), nameBuf, classBuf);
                                     if(5 == scanRes)
                                     {
                                         if('.' == nameBuf[0])
                                         {
                                             theSegment->mSegment = strdup(&nameBuf[1]);
                                         }
                                         else
                                         {