mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
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:
@ -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.");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user