From 2f136fd5ab0842e0953c9bcc60039fb88afb5134 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Tue, 2 Dec 2014 17:55:19 -0800 Subject: [PATCH] Fix some static analyzer quibbles --- diskimg/FAT.cpp | 2 +- mdc/Main.cpp | 2 +- reformat/Directory.cpp | 8 ++++---- reformat/Disasm.cpp | 2 +- util/SelectFilesDialog.cpp | 6 +++++- util/Util.cpp | 4 ++-- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/diskimg/FAT.cpp b/diskimg/FAT.cpp index 77b816c..00dc0ce 100644 --- a/diskimg/FAT.cpp +++ b/diskimg/FAT.cpp @@ -333,7 +333,7 @@ void DiskFSFAT::CreateFakeFile(void) capacity = fTotalBlocks; memset(buf, 0, sizeof(buf)); - snprintf(buf, NELEM(buf), kFormatMsg, + snprintf(buf, NELEM(buf)-1, kFormatMsg, fVolumeName, capacity, (double) capacity / 2048.0); diff --git a/mdc/Main.cpp b/mdc/Main.cpp index 4e5088a..47c89be 100644 --- a/mdc/Main.cpp +++ b/mdc/Main.cpp @@ -228,7 +228,7 @@ void MainWindow::ScanFiles(void) time_t now; now = time(NULL); fprintf(scanOpts.outfp, - "Run started at %.24hs in '%ls'\n\n", ctime(&now), newDir); + "Run started at %.24hs in '%ls'\n\n", ctime(&now), (LPCWSTR) newDir); /* obstruct input to the main window */ EnableWindow(FALSE); diff --git a/reformat/Directory.cpp b/reformat/Directory.cpp index b98e8b6..b6ea061 100644 --- a/reformat/Directory.cpp +++ b/reformat/Directory.cpp @@ -128,15 +128,15 @@ void ReformatDirectory::PrintDirEntries(const uint8_t* srcBuf, else if (pDirEntry[0x10] == 0x04) // txt auxTypeStr.Format("R=%5d", auxType); - BufPrintf("%c%-15s %-3s %6d %16s %16s %8d %s\r\n", + BufPrintf("%c%-15s %-3ls %6d %16s %16s %8d %s\r\n", lockedFlag, fileName, PathProposal::FileTypeString(pDirEntry[0x10]), pDirEntry[0x13] | pDirEntry[0x14] << 8, - modStr, - createStr, + (LPCSTR) modStr, + (LPCSTR) createStr, pDirEntry[0x15] | pDirEntry[0x16] << 8 | pDirEntry[0x17] << 16, - auxTypeStr); + (LPCSTR) auxTypeStr); } } } diff --git a/reformat/Disasm.cpp b/reformat/Disasm.cpp index c04e066..94b76e6 100644 --- a/reformat/Disasm.cpp +++ b/reformat/Disasm.cpp @@ -874,7 +874,7 @@ bool ReformatDisasm16::OutputOMF(const uint8_t* srcBuf, long srcLen, int segmentNumber = 1; BufPrintf(";\r\n"); - BufPrintf("; OMF segment summary:\r\n", segmentNumber); + BufPrintf("; OMF segment summary:\r\n"); BufPrintf(";\r\n"); /* pass #1: print a preview */ diff --git a/util/SelectFilesDialog.cpp b/util/SelectFilesDialog.cpp index 7f9a6c1..08f2e6b 100644 --- a/util/SelectFilesDialog.cpp +++ b/util/SelectFilesDialog.cpp @@ -52,6 +52,10 @@ void SelectFilesDialog2::OnFolderChange() LOGW("Can't get folder ID list, len is %d", len); } else { LPCITEMIDLIST pidlFolder = (LPCITEMIDLIST) CoTaskMemAlloc(len); + if (pidlFolder == NULL) { + LOGE("Unable to allocate %d bytes", len); + return; + } len = pParent->SendMessage(CDM_GETFOLDERIDLIST, len, (LPARAM) pidlFolder); ASSERT(len > 0); // should fail earlier, or not at all @@ -426,7 +430,7 @@ int SelectFilesDialog2::ParseFileNames(const CString& str) ASSERT(pSFD != NULL); return pSFD->HandleHelp(hDlg, (LPHELPINFO) lParam); default: - LOGV("OFNHookProc: hDlg=0x%08lx uiMsg=0x%08lx " + LOGV("OFNHookProc: hDlg=0x%p uiMsg=0x%08lx " "wParam=0x%08lx lParam=0x%08lx", hDlg, uiMsg, wParam, lParam); break; diff --git a/util/Util.cpp b/util/Util.cpp index 560c286..e7d5913 100644 --- a/util/Util.cpp +++ b/util/Util.cpp @@ -656,7 +656,7 @@ static void DowncaseSubstring(CString* pStr, int startPos, int endPos, if (prevWasSpace) { for (i = 0; i < NELEM(shortWords); i++) { if (token.CompareNoCase(shortWords[i]) == 0) { - LOGV(" No leading cap for '%ls'", token); + LOGV(" No leading cap for '%ls'", (LPCWSTR) token); firstCap = false; break; } @@ -666,7 +666,7 @@ static void DowncaseSubstring(CString* pStr, int startPos, int endPos, /* check for roman numerals; we leave those capitalized */ CString romanTest = token.SpanIncluding(L"IVX"); if (romanTest.GetLength() == token.GetLength()) { - LOGV(" Looks like roman numerals '%ls'", token); + LOGV(" Looks like roman numerals '%ls'", (LPCWSTR) token); return; }