From: <cha...@us...> - 2009-01-27 03:05:03
|
Revision: 570 http://sipp.svn.sourceforge.net/sipp/?rev=570&view=rev Author: charlespwright Date: 2009-01-27 03:04:52 +0000 (Tue, 27 Jan 2009) Log Message: ----------- Fix: Correct memory corruption reported by Artur Silveira da Cunha. Modified Paths: -------------- sipp/trunk/stat.cpp sipp/trunk/stat.hpp Modified: sipp/trunk/stat.cpp =================================================================== --- sipp/trunk/stat.cpp 2009-01-21 15:10:06 UTC (rev 569) +++ sipp/trunk/stat.cpp 2009-01-27 03:04:52 UTC (rev 570) @@ -1104,23 +1104,28 @@ int sizeOfTab, char * P_repartitionName) { - static char repartitionHeader[MAX_REPARTITION_HEADER_LENGTH]; + static char *repartitionHeader = NULL; char buffer[MAX_CHAR_BUFFER_SIZE]; + int dlen = strlen(stat_delimiter); if(tabRepartition != NULL) { + repartitionHeader = (char *)realloc(repartitionHeader, strlen(P_repartitionName) + dlen + 1); sprintf(repartitionHeader, "%s%s", P_repartitionName, stat_delimiter); for(int i=0; i<(sizeOfTab-1); i++) - { + { sprintf(buffer, "<%d%s", tabRepartition[i].borderMax, stat_delimiter); + repartitionHeader = (char *)realloc(repartitionHeader, strlen(repartitionHeader) + strlen(buffer) + 1); strcat(repartitionHeader, buffer); } sprintf(buffer, ">=%d%s", tabRepartition[sizeOfTab-1].borderMax, stat_delimiter); + repartitionHeader = (char *)realloc(repartitionHeader, strlen(repartitionHeader) + strlen(buffer) + 1); strcat(repartitionHeader, buffer); } else { - repartitionHeader[0] = '\0'; + repartitionHeader = (char *)realloc(repartitionHeader, 2); + strcpy(repartitionHeader, ""); } return(repartitionHeader); @@ -1129,23 +1134,28 @@ char* CStat::sRepartitionInfo(T_dynamicalRepartition * tabRepartition, int sizeOfTab) { - static char repartitionInfo[MAX_REPARTITION_INFO_LENGTH]; + static char *repartitionInfo; char buffer[MAX_CHAR_BUFFER_SIZE]; + int dlen = strlen(stat_delimiter); if(tabRepartition != NULL) { // if a repartition is present, this field match the repartition name + repartitionInfo = (char *)realloc(repartitionInfo, dlen + 1); sprintf(repartitionInfo, stat_delimiter); for(int i=0; i<(sizeOfTab-1); i++) { sprintf(buffer, "%lu%s", tabRepartition[i].nbInThisBorder, stat_delimiter); + repartitionInfo = (char *)realloc(repartitionInfo, strlen(repartitionInfo) + strlen(buffer) + 1); strcat(repartitionInfo, buffer); } sprintf(buffer, "%lu%s", tabRepartition[sizeOfTab-1].nbInThisBorder, stat_delimiter); + repartitionInfo = (char *)realloc(repartitionInfo, strlen(repartitionInfo) + strlen(buffer) + 1); strcat(repartitionInfo, buffer); } else { + repartitionInfo = (char *)realloc(repartitionInfo, 2); repartitionInfo[0] = '\0'; } Modified: sipp/trunk/stat.hpp =================================================================== --- sipp/trunk/stat.hpp 2009-01-21 15:10:06 UTC (rev 569) +++ sipp/trunk/stat.hpp 2009-01-27 03:04:52 UTC (rev 570) @@ -29,8 +29,6 @@ #define DEFAULT_FILE_NAME (char*)"dumpFile" #define DEFAULT_EXTENSION (char*)".csv" -#define MAX_REPARTITION_HEADER_LENGTH 1024 -#define MAX_REPARTITION_INFO_LENGTH 1024 #define MAX_CHAR_BUFFER_SIZE 1024 #include <ctime> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |