diff --git a/Source/Core/Common/Src/ChunkFile.h b/Source/Core/Common/Src/ChunkFile.h index 972e888c4b..a892f8528b 100644 --- a/Source/Core/Common/Src/ChunkFile.h +++ b/Source/Core/Common/Src/ChunkFile.h @@ -137,7 +137,7 @@ public: template void DoLinkedList(LinkedListItem **list_start) { // TODO - PanicAlert("Do(vector<>) does not yet work."); + PanicAlert("Do(linked list<>) does not yet work."); } }; diff --git a/Source/Core/Common/Src/Common.cpp b/Source/Core/Common/Src/Common.cpp index fae4cb8445..ecbec6a360 100644 --- a/Source/Core/Common/Src/Common.cpp +++ b/Source/Core/Common/Src/Common.cpp @@ -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 { diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index 9ace3e1899..ecbc9f2715 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -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) { diff --git a/Source/Core/Common/Src/StringUtil.h b/Source/Core/Common/Src/StringUtil.h index 446876e560..5604fd64db 100644 --- a/Source/Core/Common/Src/StringUtil.h +++ b/Source/Core/Common/Src/StringUtil.h @@ -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); diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp index 4c7d8c4868..689de242ae 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp +++ b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp @@ -40,9 +40,9 @@ void CEXIMemoryCard::FlushCallback(u64 userdata, int cyclesLate) } CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rFilename, int _card_index) : - m_strFilename(_rFilename) + m_strFilename(_rFilename), + card_index(_card_index) { - this->card_index = _card_index; cards[_card_index] = this; et_this_card = CoreTiming::RegisterEvent(_rName.c_str(), FlushCallback); @@ -71,10 +71,12 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF pFile = fopen(m_strFilename.c_str(), "rb"); if (pFile) { - fseek( pFile, 0L, SEEK_END ); - u64 MemFileSize = ftell( pFile ); - - switch ((MemFileSize / (8 * 1024))-5) // Convert the filesize in bytes to the "nintendo-size" + // Measure size of the memcard file. + fseek(pFile, 0L, SEEK_END); + u64 MemFileSize = ftell(pFile); + fseek(pFile, 0L, SEEK_SET); + + switch ((MemFileSize / (8 * 1024)) - 5) // Convert the filesize in bytes to the "nintendo-size" { case 59: nintendo_card_id = 0x00000004; @@ -103,9 +105,6 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF break; } - // Return to start otherwise the mem card is "corrupt" - fseek( pFile,0L,SEEK_SET); - memory_card_content = new u8[memory_card_size]; memset(memory_card_content, 0xFF, memory_card_size); @@ -124,7 +123,7 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF LOG(EXPANSIONINTERFACE, "No memory card found. Will create new."); Flush(); - Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", m_strFilename.c_str()), 4000); + Core::DisplayMessage(StringFromFormat("Wrote memory card %i contents to %s.", card_index + 1, m_strFilename.c_str()), 4000); } } @@ -149,8 +148,9 @@ void CEXIMemoryCard::Flush(bool exiting) } fwrite(memory_card_content, memory_card_size, 1, pFile); fclose(pFile); - if (!exiting) - Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", GetFileName().c_str()), 4000); + if (!exiting) { + Core::DisplayMessage(StringFromFormat("Wrote memory card %i contents to %s.", card_index, m_strFilename.c_str()).c_str(), 4000); + } } diff --git a/Source/Core/Core/Src/PatchEngine.cpp b/Source/Core/Core/Src/PatchEngine.cpp index 9abb493ad0..16b6117c9c 100644 --- a/Source/Core/Core/Src/PatchEngine.cpp +++ b/Source/Core/Core/Src/PatchEngine.cpp @@ -39,6 +39,14 @@ using namespace Common; namespace PatchEngine { +const char *PatchTypeStrings[] = +{ + "byte", + "word", + "dword", + 0 +}; + std::vector onFrame; std::map speedHacks; diff --git a/Source/Core/Core/Src/PatchEngine.h b/Source/Core/Core/Src/PatchEngine.h index ee2fc6d9c9..8896027f2c 100644 --- a/Source/Core/Core/Src/PatchEngine.h +++ b/Source/Core/Core/Src/PatchEngine.h @@ -30,13 +30,7 @@ enum PatchType PATCH_32BIT, }; -static const char *PatchTypeStrings[] = -{ - "byte", - "word", - "dword", - 0 -}; +extern const char *PatchTypeStrings[]; struct PatchEntry { diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index 92c20dfe2f..764a106cb7 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -628,7 +628,7 @@ void CGameListCtrl::OnProperties(wxCommandEvent& WXUNUSED (event)) void CGameListCtrl::MultiCompressCB(const char* text, float percent, void* arg) { - wxString textString(wxString::Format(wxT("%s (%i/%i) - %s"), m_currentFilename.c_str(), m_currentItem+1, m_numberItem, text)); + wxString textString(wxString::Format(wxT("%s (%i/%i) - %s"), m_currentFilename.c_str(), (int)m_currentItem+1, (int)m_numberItem, text)); percent = (((float)m_currentItem) + percent) / (float)m_numberItem; wxProgressDialog* pDialog = (wxProgressDialog*)arg;