Browse Source

max out the characters we load for past searches

sabrogden 6 years ago
parent
commit
32fbadfc45
3 changed files with 24 additions and 5 deletions
  1. 18 3
      Options.cpp
  2. 1 1
      Options.h
  3. 5 1
      SymbolEdit.cpp

+ 18 - 3
Options.cpp

@@ -510,7 +510,7 @@ long CGetSetOptions::GetProfileLong(CString csName, long lDefaultValue, CString
 	return lDefaultValue;
 }
 
-CString CGetSetOptions::GetProfileString(CString csName, CString csDefault, CString csNewPath)
+CString CGetSetOptions::GetProfileString(CString csName, CString csDefault, CString csNewPath, int maxSize)
 {
 	CString returnString;
 	DWORD dwBufLen = 0;
@@ -526,14 +526,22 @@ CString CGetSetOptions::GetProfileString(CString csName, CString csDefault, CStr
 
 		bool doBreak = false;
 		dwBufLen = 10000;
+		bool setMaxSize = false;
 		while (true)
 		{
+			if (maxSize > -1 && maxSize < dwBufLen)
+			{
+				dwBufLen = maxSize;
+				setMaxSize = true;
+			}
+
 			TCHAR *szString = new TCHAR[dwBufLen];
 			ZeroMemory(szString, dwBufLen);
 
 			DWORD readLength = GetPrivateProfileString(csApp, csName, csDefault, szString, dwBufLen, m_csIniFileName);
 
-			if (readLength < (dwBufLen - 1))
+			if (setMaxSize ||
+				readLength < (dwBufLen - 1))
 			{
 				returnString = szString;
 				doBreak = true; //delay break so we can delete the string
@@ -567,6 +575,11 @@ CString CGetSetOptions::GetProfileString(CString csName, CString csDefault, CStr
 		if (lResult == ERROR_SUCCESS &&
 			dwBufLen > 0)
 		{
+			if (maxSize > -1 && maxSize < dwBufLen)
+			{
+				dwBufLen = maxSize;
+			}
+
 			dwBufLen++;
 			TCHAR *szString = new TCHAR[dwBufLen];
 			ZeroMemory(szString, dwBufLen);
@@ -2700,7 +2713,9 @@ void CGetSetOptions::SetToolTipTimeout(long val)
 
 CString CGetSetOptions::GetPastSearchXml()
 {
-	return GetProfileString("PastSearchXml", "");
+	//max this out at 100000, this should be more than the allowed length in SymbolEdit.cpp
+	//had reports of this being really large and causing memory issues, this will prevent us from this
+	return GetProfileString("PastSearchXml", "", "", 100000);
 }
 
 void CGetSetOptions::SetPastSearchXml(CString val)

+ 1 - 1
Options.h

@@ -100,7 +100,7 @@ public:
 	static BOOL SetProfileLong(CString csName, long lValue);
 	static long GetProfileLong(CString csName, long lDefaultValue = -1, CString csNewPath = _T(""));
 
-	static CString GetProfileString(CString csName, CString csDefault, CString csNewPath = _T(""));
+	static CString GetProfileString(CString csName, CString csDefault, CString csNewPath = _T(""), int maxSize = -1);
 	static BOOL	SetProfileString(CString csName, CString csValue);
 
 	static LPVOID GetProfileData(CString csName, DWORD &dwLength);

+ 5 - 1
SymbolEdit.cpp

@@ -233,7 +233,11 @@ void CSymbolEdit::LoadPastSearches(CString values)
 		{
 			CString item = ItemElement->Attribute("text");
 
-			m_searches.Add(item.Left(MAX_SAVED_SEARCH_LENGTH));
+			CString toAdd = item.Left(MAX_SAVED_SEARCH_LENGTH);
+			if (toAdd != _T(""))
+			{
+				m_searches.Add(toAdd);
+			}
 
 			ItemElement = ItemElement->NextSiblingElement();
 		}