From 665d8e54227d45b6352ac9ff9d7700073a08977d Mon Sep 17 00:00:00 2001 From: spx Date: Wed, 17 Aug 2011 18:16:13 +0000 Subject: [PATCH] Magic sequence: Fixed some infinite loop issues. --- Library/Rainmeter.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 5c661458..630694c2 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -59,16 +59,23 @@ std::vector CRainmeter::ParseString(LPCTSTR str) { if (arg[pos] == L'"') { - if (arg[pos + 1] == L'"' && arg[pos + 2] == L'"') + if (arg.size() > (pos + 2) && + arg[pos + 1] == L'"' && arg[pos + 2] == L'"') { // Eat found quotes and finding ending """ arg.erase(0, pos + 3); - pos = arg.find(L"\"\"\" "); + + size_t extra = 4; + if ((pos = arg.find(L"\"\"\" ")) == std::wstring::npos) + { + extra = 3; + pos = arg.find(L"\"\"\""); + } if (pos != std::wstring::npos) { newStr.assign(arg, 0, pos); - arg.erase(0, pos + 4); + arg.erase(0, pos + extra); result.push_back(newStr); } @@ -80,7 +87,7 @@ std::vector CRainmeter::ParseString(LPCTSTR str) { // Eat found quote and find ending quote arg.erase(0, pos + 1); - pos = arg.find_first_of(L"\""); + pos = arg.find_first_of(L'"'); } } else @@ -101,17 +108,27 @@ std::vector CRainmeter::ParseString(LPCTSTR str) arg.erase(0, pos + 1); // Strip quotes - while ((pos = newStr.find(L"\"")) != std::wstring::npos) + while ((pos = newStr.find(L'"')) != std::wstring::npos) { newStr.erase(pos, 1); } result.push_back(newStr); } + else // quote or space not found + { + break; + } } if (arg.size() > 0) { + // Strip quotes + while ((pos = arg.find(L'"')) != std::wstring::npos) + { + arg.erase(pos, 1); + } + result.push_back(arg); } }