summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2011-11-19 17:50:12 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2011-11-19 17:50:12 +0800
commitf793bb617444e0b365e60e731b56a805bea53894 (patch)
tree0c94a0fd8893e5642300da76a9b31fbc32114040
parentae0e722efddd0d5f290ada815c1e12dc636a96a5 (diff)
SexyAppFramework: Enlarge the buffer for the StrFormat
-rw-r--r--osframework/source/SexyAppFramework/Common.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/osframework/source/SexyAppFramework/Common.cpp b/osframework/source/SexyAppFramework/Common.cpp
index 0ba966f..fd11918 100644
--- a/osframework/source/SexyAppFramework/Common.cpp
+++ b/osframework/source/SexyAppFramework/Common.cpp
@@ -574,7 +574,7 @@ SexyString Sexy::CommaSeperate(int theValue)
{
if ((aPlace != 0) && (aPlace % 3 == 0))
aCurString = ',' + aCurString;
- aCurString = (SexyChar) ('0' + (aCurValue % 10)) + aCurString;
+ aCurString = (char)('0' + (aCurValue % 10)) + aCurString;
aCurValue /= 10;
aPlace++;
}
@@ -964,16 +964,16 @@ time_t Sexy::GetFileDate(const std::string& theFileName)
std::string Sexy::vformat(const char* fmt, va_list argPtr)
{
- // We draw the line at a 1MB string.
- const int maxSize = 1000000;
+ // We draw the line at a 1MB string.
+ const int maxSize = 1000000;
- // If the string is less than 161 characters,
- // allocate it on the stack because this saves
- // the malloc/free time.
- const int bufSize = 161;
+ // If the string is less than 1024 characters,
+ // allocate it on the stack because this saves
+ // the malloc/free time.
+ const int bufSize = 2049;
char stackBuffer[bufSize];
- int attemptedSize = bufSize - 1;
+ int attemptedSize = bufSize - 1;
int numChars = 0;
#ifdef _WIN32
@@ -984,37 +984,37 @@ std::string Sexy::vformat(const char* fmt, va_list argPtr)
//cout << "NumChars: " << numChars << endl;
- if ((numChars >= 0) && (numChars <= attemptedSize))
+ if ((numChars >= 0) && (numChars <= attemptedSize))
{
- // Needed for case of 160-character printf thing
+ // Needed for case of 2048-character printf thing
stackBuffer[numChars] = '\0';
- // Got it on the first try.
+ // Got it on the first try.
return std::string(stackBuffer);
- }
+ }
- // Now use the heap.
- char* heapBuffer = NULL;
+ // Now use the heap.
+ char* heapBuffer = NULL;
- while (((numChars == -1) || (numChars > attemptedSize)) &&
- (attemptedSize < maxSize))
+ while (((numChars == -1) || (numChars > attemptedSize)) &&
+ (attemptedSize < maxSize))
{
- // Try a bigger size
- attemptedSize *= 2;
+ // Try a bigger size
+ attemptedSize *= 2;
heapBuffer = (char*)realloc(heapBuffer, (attemptedSize + 1));
#ifdef _WIN32
numChars = _vsnprintf(heapBuffer, attemptedSize, fmt, argPtr);
#else
numChars = vsnprintf(heapBuffer, attemptedSize, fmt, argPtr);
#endif
- }
+ }
heapBuffer[numChars] = 0;
std::string result = std::string(heapBuffer);
- free(heapBuffer);
- return result;
+ free(heapBuffer);
+ return result;
}
//overloaded StrFormat: should only be used by the xml strings