Workaround for StringFromFormat-under-linux problem, random cleanup.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1491 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard
2008-12-10 22:36:26 +00:00
parent 61392ba692
commit 0ad52a4fee
8 changed files with 62 additions and 47 deletions

View File

@ -137,7 +137,7 @@ public:
template<class T>
void DoLinkedList(LinkedListItem<T> **list_start) {
// TODO
PanicAlert("Do(vector<>) does not yet work.");
PanicAlert("Do(linked list<>) does not yet work.");
}
};

View File

@ -38,10 +38,10 @@ void PanicAlert(const char* format, ...)
if (panic_handler)
{
std::string msg;
StringFromFormatV(&msg, format, args);
LOG(MASTER_LOG, "PANIC: %s", msg.c_str());
panic_handler(msg.c_str(), false);
char buffer[2048];
CharArrayFromFormatV(buffer, 2048, format, args);
LOG(MASTER_LOG, "PANIC: %s", buffer);
panic_handler(buffer, false);
}
else
{

View File

@ -85,19 +85,23 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
// Expensive!
void StringFromFormatV(std::string* out, const char* format, va_list args)
void ToStringFromFormat(std::string* out, const char* format, ...)
{
int writtenCount = -1;
size_t newSize = strlen(format) + 16;
char* buf = 0;
int newSize = (int)strlen(format) + 4;
char *buf = 0;
va_list args;
while (writtenCount < 0)
{
delete [] buf;
buf = new char[newSize + 1];
va_start(args, format);
writtenCount = vsnprintf(buf, newSize, format, args);
if (writtenCount > (int)newSize)
va_end(args);
if (writtenCount >= (int)newSize) {
writtenCount = -1;
}
// ARGH! vsnprintf does no longer return -1 on truncation in newer libc!
// WORKAROUND! let's fake the old behaviour (even though it's less efficient).
// TODO: figure out why the fix causes an invalid read in strlen called from vsnprintf :(
@ -114,12 +118,32 @@ void StringFromFormatV(std::string* out, const char* format, va_list args)
std::string StringFromFormat(const char* format, ...)
{
std::string temp;
int writtenCount = -1;
int newSize = (int)strlen(format) + 4;
char *buf = 0;
va_list args;
va_start(args, format);
StringFromFormatV(&temp, format, args);
va_end(args);
return(temp);
while (writtenCount < 0)
{
delete [] buf;
buf = new char[newSize + 1];
va_start(args, format);
writtenCount = vsnprintf(buf, newSize, format, args);
va_end(args);
if (writtenCount >= (int)newSize) {
writtenCount = -1;
}
// ARGH! vsnprintf does no longer return -1 on truncation in newer libc!
// WORKAROUND! let's fake the old behaviour (even though it's less efficient).
// TODO: figure out why the fix causes an invalid read in strlen called from vsnprintf :(
// if (writtenCount >= (int)newSize)
// writtenCount = -1;
newSize *= 2;
}
buf[writtenCount] = '\0';
std::string temp = buf;
return temp;
}
@ -142,15 +166,6 @@ std::string ArrayToString(const u8 *data, u32 size, u32 offset, int line_len)
// ================
void ToStringFromFormat(std::string* out, const char* format, ...)
{
va_list args;
va_start(args, format);
StringFromFormatV(out, format, args);
va_end(args);
}
// Turns " hej " into "hej". Also handles tabs.
std::string StripSpaces(const std::string &str)
{

View File

@ -28,10 +28,8 @@
std::string StringFromFormat(const char* format, ...);
void ToStringFromFormat(std::string* out, const char* format, ...);
// Expensive!
// WARNING - only call once with a set of args!
void StringFromFormatV(std::string* out, const char* format, va_list args);
// Cheap!
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args);