Index: SubWCRev/UnicodeUtils.cpp
===================================================================
--- SubWCRev/UnicodeUtils.cpp	(revision 18191)
+++ SubWCRev/UnicodeUtils.cpp	(working copy)
@@ -15,20 +15,19 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #include "StdAfx.h"
 #include "UnicodeUtils.h"
+#include "auto_buffer.h"
 
-
 char * AnsiToUtf8(const char * pszAnsi, apr_pool_t *pool)
 {
 	// convert ANSI --> UTF16
 	int utf16_count = MultiByteToWideChar(CP_ACP, 0, pszAnsi, -1, NULL, 0);
-	WCHAR * pwc = new WCHAR[utf16_count];
+	auto_buffer<WCHAR> pwc(utf16_count);
 	MultiByteToWideChar(CP_ACP, 0, pszAnsi, -1, pwc, utf16_count);
 
 	// and now from URF16 --> UTF-8
 	int utf8_count = WideCharToMultiByte(CP_UTF8, 0, pwc, utf16_count, NULL, 0, NULL, NULL);
 	char * pch = (char*) apr_palloc(pool, utf8_count);
 	WideCharToMultiByte(CP_UTF8, 0, pwc, utf16_count, pch, utf8_count, NULL, NULL);
-	delete[] pwc;
 	return pch;
 }
 
Index: TortoiseProc/AppUtils.cpp
===================================================================
--- TortoiseProc/AppUtils.cpp	(revision 18191)
+++ TortoiseProc/AppUtils.cpp	(working copy)
@@ -459,20 +459,18 @@
 		// lookup by verb
 		DWORD buflen = 0;
 		AssocQueryString(ASSOCF_INIT_DEFAULTTOSTAR, ASSOCSTR_COMMAND, extensionToUse, verb, NULL, &buflen);
-		TCHAR * cmdbuf = new TCHAR[buflen + 1];
+		auto_buffer<TCHAR> cmdbuf(buflen + 1);
 		AssocQueryString(ASSOCF_INIT_DEFAULTTOSTAR, ASSOCSTR_COMMAND, extensionToUse, verb, cmdbuf, &buflen);
 		application = cmdbuf;
-		delete [] cmdbuf;
 
 		// fallback to "open"
 
 		if (application.IsEmpty())
 		{
 			AssocQueryString(ASSOCF_INIT_DEFAULTTOSTAR, ASSOCSTR_COMMAND, extensionToUse, _T("open"), NULL, &buflen);
-			cmdbuf = new TCHAR[buflen + 1];
+			cmdbuf.reset(buflen + 1);
 			AssocQueryString(ASSOCF_INIT_DEFAULTTOSTAR, ASSOCSTR_COMMAND, extensionToUse, _T("open"), cmdbuf, &buflen);
 			application = cmdbuf;
-			delete [] cmdbuf;
 		}
 	}
 
@@ -719,12 +717,7 @@
 		{
 			CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
 			pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
-			CHARFORMAT2 format;
-			SecureZeroMemory(&format, sizeof(CHARFORMAT2));
-			format.cbSize = sizeof(CHARFORMAT2);
-			format.dwMask = CFM_BOLD;
-			format.dwEffects = CFE_BOLD;
-			pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+			SetCharFormat(pWnd, CFM_BOLD, CFE_BOLD);
 			bStyled = true;
 			start = end;
 		}
@@ -734,12 +727,7 @@
 		{
 			CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
 			pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
-			CHARFORMAT2 format;
-			SecureZeroMemory(&format, sizeof(CHARFORMAT2));
-			format.cbSize = sizeof(CHARFORMAT2);
-			format.dwMask = CFM_ITALIC;
-			format.dwEffects = CFE_ITALIC;
-			pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+			SetCharFormat(pWnd, CFM_ITALIC, CFE_ITALIC);
 			bStyled = true;
 			start = end;
 		}
@@ -749,12 +737,7 @@
 		{
 			CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
 			pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
-			CHARFORMAT2 format;
-			SecureZeroMemory(&format, sizeof(CHARFORMAT2));
-			format.cbSize = sizeof(CHARFORMAT2);
-			format.dwMask = CFM_UNDERLINE;
-			format.dwEffects = CFE_UNDERLINE;
-			pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+			SetCharFormat(pWnd, CFM_UNDERLINE, CFE_UNDERLINE);
 			bStyled = true;
 			start = end;
 		}
@@ -791,12 +774,7 @@
 				ptrdiff_t matchposID = it2->position(0);
 				CHARRANGE range = {(LONG)(matchpos+matchposID), (LONG)(matchpos+matchposID+(*it2)[0].str().size())};
 				pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
-				CHARFORMAT2 format;
-				SecureZeroMemory(&format, sizeof(CHARFORMAT2));
-				format.cbSize = sizeof(CHARFORMAT2);
-				format.dwMask = CFM_LINK;
-				format.dwEffects = CFE_LINK;
-				pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+				SetCharFormat(pWnd, CFM_LINK, CFE_LINK);
 				bFound = true;
 			}
 		}
@@ -1370,4 +1348,13 @@
 		}
 	}
 	return url;
-}
\ No newline at end of file
+}
+
+void CAppUtils::SetCharFormat(CWnd* window, DWORD mask, DWORD effects )
+{
+	CHARFORMAT2 format = {};
+	format.cbSize = sizeof(CHARFORMAT2);
+	format.dwMask = mask;
+	format.dwEffects = effects;
+	window->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+}
Index: TortoiseProc/AppUtils.h
===================================================================
--- TortoiseProc/AppUtils.h	(revision 18191)
+++ TortoiseProc/AppUtils.h	(working copy)
@@ -241,4 +241,5 @@
 private:
 	static CString PickDiffTool(const CTSVNPath& file1, const CTSVNPath& file2);
 	static bool GetMimeType(const CTSVNPath& file, CString& mimetype);
+	static void SetCharFormat(CWnd* window, DWORD mask, DWORD effects );
 };
Index: TortoiseProc/ProjectProperties.cpp
===================================================================
--- TortoiseProc/ProjectProperties.cpp	(revision 18191)
+++ TortoiseProc/ProjectProperties.cpp	(working copy)
@@ -413,12 +413,7 @@
 						ptrdiff_t matchposID = it2->position(0);
 						CHARRANGE range = {(LONG)(matchpos+matchposID), (LONG)(matchpos+matchposID+(*it2)[0].str().size())};
 						pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
-						CHARFORMAT2 format;
-						SecureZeroMemory(&format, sizeof(CHARFORMAT2));
-						format.cbSize = sizeof(CHARFORMAT2);
-						format.dwMask = CFM_LINK;
-						format.dwEffects = CFE_LINK;
-						pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+						SetLinkCharFormat(pWnd);
 						bFound = true;
 					}
 				}
@@ -442,12 +437,7 @@
 						ATLTRACE(_T("matched id : %s\n"), wstring(match[1]).c_str());
 						CHARRANGE range = {(LONG)(match[1].first-s.begin()), (LONG)(match[1].second-s.begin())};
 						pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
-						CHARFORMAT2 format;
-						SecureZeroMemory(&format, sizeof(CHARFORMAT2));
-						format.cbSize = sizeof(CHARFORMAT2);
-						format.dwMask = CFM_LINK;
-						format.dwEffects = CFE_LINK;
-						pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+						SetLinkCharFormat(pWnd);
 						bFound = true;
 					}
 				}
@@ -509,24 +499,14 @@
 			offset2 = offset1 + sBugIDPart.Find(',');
 			CHARRANGE range = {(LONG)offset1, (LONG)offset2};
 			pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
-			CHARFORMAT2 format;
-			SecureZeroMemory(&format, sizeof(CHARFORMAT2));
-			format.cbSize = sizeof(CHARFORMAT2);
-			format.dwMask = CFM_LINK;
-			format.dwEffects = CFE_LINK;
-			pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+			SetLinkCharFormat(pWnd);
 			sBugIDPart = sBugIDPart.Mid(sBugIDPart.Find(',')+1);
 			offset1 = offset2 + 1;
 		}
 		offset2 = offset1 + sBugIDPart.GetLength();
 		CHARRANGE range = {(LONG)offset1, (LONG)offset2};
 		pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
-		CHARFORMAT2 format;
-		SecureZeroMemory(&format, sizeof(CHARFORMAT2));
-		format.cbSize = sizeof(CHARFORMAT2);
-		format.dwMask = CFM_LINK;
-		format.dwEffects = CFE_LINK;
-		pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+		SetLinkCharFormat(pWnd);
 		return TRUE;
 	}
 	return FALSE;
@@ -874,6 +854,15 @@
 	return sShortMessage;
 }
 
+void ProjectProperties::SetLinkCharFormat(CWnd* window)
+{
+	CHARFORMAT2 format = {};
+	format.cbSize = sizeof(CHARFORMAT2);
+	format.dwMask = CFM_LINK;
+	format.dwEffects = CFE_LINK;
+	window->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
+}
+
 #ifdef DEBUG
 static class PropTest
 {
@@ -923,5 +912,3 @@
 } PropTest;
 #endif
 
-
-
Index: TortoiseProc/ProjectProperties.h
===================================================================
--- TortoiseProc/ProjectProperties.h	(revision 18191)
+++ TortoiseProc/ProjectProperties.h	(working copy)
@@ -255,5 +255,5 @@
 	
 	/** used to extract the bug ID from the string matched by sCheckRe */
 	CString		sBugIDRe;
-	
+	static void SetLinkCharFormat(CWnd* window);
 };
Index: TortoiseProc/PropDlg.cpp
===================================================================
--- TortoiseProc/PropDlg.cpp	(revision 18191)
+++ TortoiseProc/PropDlg.cpp	(working copy)
@@ -66,13 +66,7 @@
 	temp.LoadString(IDS_PROPVALUE);
 	m_proplist.InsertColumn(1, temp);
 	m_proplist.SetRedraw(false);
-	int mincol = 0;
-	int maxcol = ((CHeaderCtrl*)(m_proplist.GetDlgItem(0)))->GetItemCount()-1;
-	int col;
-	for (col = mincol; col <= maxcol; col++)
-	{
-		m_proplist.SetColumnWidth(col,LVSCW_AUTOSIZE_USEHEADER);
-	}
+	setProplistColumnWidth();
 	m_proplist.SetRedraw(false);
 
 	DialogEnableWindow(IDOK, FALSE);
@@ -130,13 +124,7 @@
 			name.Empty();
 		} while (!val.IsEmpty()&&(nFound>=0));
 	}
-	int mincol = 0;
-	int maxcol = ((CHeaderCtrl*)(m_proplist.GetDlgItem(0)))->GetItemCount()-1;
-	int col;
-	for (col = mincol; col <= maxcol; col++)
-	{
-		m_proplist.SetColumnWidth(col,LVSCW_AUTOSIZE_USEHEADER);
-	}
+	setProplistColumnWidth();
 
 	m_proplist.SetRedraw(true);
 	DialogEnableWindow(IDOK, TRUE);
@@ -155,3 +143,12 @@
 	SetCursor(hCur);
 	return TRUE;
 }
+
+void CPropDlg::setProplistColumnWidth()
+{
+	const int maxcol = ((CHeaderCtrl*)(m_proplist.GetDlgItem(0)))->GetItemCount()-1;
+	for (int col = 0; col <= maxcol; col++)
+	{
+		m_proplist.SetColumnWidth(col,LVSCW_AUTOSIZE_USEHEADER);
+	}
+}
Index: TortoiseProc/PropDlg.h
===================================================================
--- TortoiseProc/PropDlg.h	(revision 18191)
+++ TortoiseProc/PropDlg.h	(working copy)
@@ -56,5 +56,7 @@
 	HANDLE		m_hThread;
 	CListCtrl	m_proplist;
 	AeroControlBase m_aeroControls;
+
+	void setProplistColumnWidth();
 };
 
Index: Utils/CreateProcessHelper.h
===================================================================
--- Utils/CreateProcessHelper.h	(revision 18191)
+++ Utils/CreateProcessHelper.h	(working copy)
@@ -39,11 +39,9 @@
 	LPTSTR commandLine, LPCTSTR currentDirectory,
 	LPPROCESS_INFORMATION processInfo)
 {
-	STARTUPINFO startupInfo;
-	memset(&startupInfo, 0, sizeof(STARTUPINFO));
+	STARTUPINFO startupInfo = {};
 	startupInfo.cb = sizeof(STARTUPINFO);
 
-	memset(processInfo, 0, sizeof(PROCESS_INFORMATION));
 	const BOOL result = ::CreateProcess( applicationName,
 					commandLine, NULL, NULL, FALSE, 0, 0, currentDirectory,
 					&startupInfo, processInfo );
Index: Utils/MiscUI/IconBitmapUtils.cpp
===================================================================
--- Utils/MiscUI/IconBitmapUtils.cpp	(revision 18191)
+++ Utils/MiscUI/IconBitmapUtils.cpp	(working copy)
@@ -190,10 +190,15 @@
 
 HRESULT IconBitmapUtils::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp)
 {
+	if (psize == 0)
+		return E_INVALIDARG;
+
+	if (phBmp == 0)
+		return E_POINTER;
+
 	*phBmp = NULL;
 
-	BITMAPINFO bmi;
-	SecureZeroMemory(&bmi, sizeof(bmi));
+	BITMAPINFO bmi = {};
 	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 	bmi.bmiHeader.biPlanes = 1;
 	bmi.bmiHeader.biCompression = BI_RGB;
@@ -262,8 +267,7 @@
 
 HRESULT IconBitmapUtils::ConvertToPARGB32(HDC hdc, __inout Gdiplus::ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
 {
-	BITMAPINFO bmi;
-	SecureZeroMemory(&bmi, sizeof(bmi));
+	BITMAPINFO bmi = {};
 	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 	bmi.bmiHeader.biPlanes = 1;
 	bmi.bmiHeader.biCompression = BI_RGB;
@@ -272,41 +276,38 @@
 	bmi.bmiHeader.biHeight = sizImage.cy;
 	bmi.bmiHeader.biBitCount = 32;
 
-	HRESULT hr = E_OUTOFMEMORY;
 	HANDLE hHeap = GetProcessHeap();
 	void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight);
-	if (pvBits)
+	if (pvBits == 0)
+		return E_OUTOFMEMORY;
+
+	HRESULT hr = E_UNEXPECTED;
+	if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
 	{
-		hr = E_UNEXPECTED;
-		if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight)
+		ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
+		Gdiplus::ARGB *pargbMask = static_cast<Gdiplus::ARGB *>(pvBits);
+
+		for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
 		{
-			ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
-            Gdiplus::ARGB *pargbMask = static_cast<Gdiplus::ARGB *>(pvBits);
-
-			for (ULONG y = bmi.bmiHeader.biHeight; y; --y)
+			for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
 			{
-				for (ULONG x = bmi.bmiHeader.biWidth; x; --x)
+				if (*pargbMask++)
 				{
-					if (*pargbMask++)
-					{
-						// transparent pixel
-						*pargb++ = 0;
-					}
-					else
-					{
-						// opaque pixel
-						*pargb++ |= 0xFF000000;
-					}
+					// transparent pixel
+					*pargb++ = 0;
 				}
-
-				pargb += cxDelta;
+				else
+				{
+					// opaque pixel
+					*pargb++ |= 0xFF000000;
+				}
 			}
-
-			hr = S_OK;
+			pargb += cxDelta;
 		}
 
-		HeapFree(hHeap, 0, pvBits);
+		hr = S_OK;
 	}
+	HeapFree(hHeap, 0, pvBits);
 
 	return hr;
 }
Index: Utils/PathWatcher.cpp
===================================================================
--- Utils/PathWatcher.cpp	(revision 18191)
+++ Utils/PathWatcher.cpp	(working copy)
@@ -187,7 +187,8 @@
 	DWORD numBytes;
 	CDirWatchInfo * pdi = NULL;
 	LPOVERLAPPED lpOverlapped;
-	WCHAR buf[MAX_PATH*4] = {0};
+	const int bufferSize = MAX_PATH * 4;
+	TCHAR buf[bufferSize] = {0};
 	while (m_bRunning)
 	{
 		if (watchedPaths.GetCount())
@@ -288,15 +289,15 @@
 					do 
 					{
 						nOffset = pnotify->NextEntryOffset;
-						SecureZeroMemory(buf, MAX_PATH*4*sizeof(TCHAR));
-						_tcsncpy_s(buf, MAX_PATH*4, pdi->m_DirPath, MAX_PATH*4);
-						errno_t err = _tcsncat_s(buf+pdi->m_DirPath.GetLength(), (MAX_PATH*4)-pdi->m_DirPath.GetLength(), pnotify->FileName, _TRUNCATE);
+						SecureZeroMemory(buf, bufferSize*sizeof(TCHAR));
+						_tcsncpy_s(buf, bufferSize, pdi->m_DirPath, bufferSize);
+						errno_t err = _tcsncat_s(buf+pdi->m_DirPath.GetLength(), (bufferSize)-pdi->m_DirPath.GetLength(), pnotify->FileName, _TRUNCATE);
 						if (err == STRUNCATE)
 						{
 							pnotify = (PFILE_NOTIFY_INFORMATION)((LPBYTE)pnotify + nOffset);
 							continue;
 						}
-						buf[min(MAX_PATH*4-1, pdi->m_DirPath.GetLength()+(pnotify->FileNameLength/sizeof(WCHAR)))] = 0;
+						buf[min(bufferSize-1, pdi->m_DirPath.GetLength()+(pnotify->FileNameLength/sizeof(WCHAR)))] = 0;
 						pnotify = (PFILE_NOTIFY_INFORMATION)((LPBYTE)pnotify + nOffset);
 						ATLTRACE(_T("change notification: %s\n"), buf);
 						m_changedPaths.AddPath(CTSVNPath(buf));
Index: Utils/PersonalDictionary.cpp
===================================================================
--- Utils/PersonalDictionary.cpp	(revision 18191)
+++ Utils/PersonalDictionary.cpp	(working copy)
@@ -51,15 +51,13 @@
 	_tcscat_s(path, MAX_PATH, _T(".dic"));
 
 	std::wifstream File;
-	char filepath[MAX_PATH+1];
-	SecureZeroMemory(filepath, sizeof(filepath));
+	char filepath[MAX_PATH+1] = {};
 	WideCharToMultiByte(CP_ACP, NULL, path, -1, filepath, MAX_PATH, NULL, NULL);
 	File.open(filepath);
 	if (!File.good())
 	{
 		return false;
 	}
-	std::vector<std::wstring> entry;
 	do
 	{
 		File.getline(line, sizeof(line)/sizeof(TCHAR));
@@ -109,8 +107,7 @@
 	_tcscat_s(path, MAX_PATH, _T(".dic"));
 
 	std::wofstream File;
-	char filepath[MAX_PATH+1];
-	SecureZeroMemory(filepath, sizeof(filepath));
+	char filepath[MAX_PATH+1] = {};
 	WideCharToMultiByte(CP_ACP, NULL, path, -1, filepath, MAX_PATH, NULL, NULL);
 	File.open(filepath, std::ios_base::binary);
 	for (std::set<CString>::iterator it = dict.begin(); it != dict.end(); ++it)
