From 087616db294893cb89806e1e7e32afde8e0855d5 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 4 Jan 2020 17:43:20 +0000 Subject: [PATCH] Fixed Coverity 'High Impact Outstanding' issues: 1489113 1489111 1489105 1489096 1489093 1489092 1486059 1486055 (false positive) 1486054 1486051 (false positive) 1486050 1486047 (false positive) 1486043 1446684 --- source/Applewin.cpp | 4 +--- source/Debugger/Debug.cpp | 2 +- source/Debugger/Debugger_DisassemblerData.cpp | 2 +- source/DiskImageHelper.cpp | 16 ++++++++++------ source/Memory.cpp | 4 ++-- test/TestDebugger/TestDebugger.cpp | 12 ++++++++++-- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index 171e92d8..52777d4f 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -1682,9 +1682,7 @@ static void GetAppleWinVersion(void) char szPath[_MAX_PATH]; if (0 == GetModuleFileName(NULL, szPath, sizeof(szPath))) - { - strcpy(szPath, __argv[0]); - } + strcpy_s(szPath, sizeof(szPath), __argv[0]); // Extract application version and store in a global variable DWORD dwHandle, dwVerInfoSize; diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index f2de9b41..8bb66590 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -7037,7 +7037,7 @@ Update_t CmdWatchAdd (int nArgs) if (iWatch == NO_6502_TARGET) { iWatch = 0; - while ((iWatch < MAX_ZEROPAGE_POINTERS) && (g_aWatches[iWatch].bSet)) + while ((iWatch < MAX_WATCHES) && (g_aWatches[iWatch].bSet)) { iWatch++; } diff --git a/source/Debugger/Debugger_DisassemblerData.cpp b/source/Debugger/Debugger_DisassemblerData.cpp index 0eded8e1..43f256ed 100644 --- a/source/Debugger/Debugger_DisassemblerData.cpp +++ b/source/Debugger/Debugger_DisassemblerData.cpp @@ -125,7 +125,7 @@ WORD _CmdDefineByteRange(int nArgs,int iArg,DisasmData_t & tData_) // TODO: Note: need to call ConsoleUpdate(), as may print symbol has been updated - strcpy( tData_.sSymbol, pSymbolName ); + strcpy_s( tData_.sSymbol, sizeof(tData_.sSymbol), pSymbolName ); return nAddress; } diff --git a/source/DiskImageHelper.cpp b/source/DiskImageHelper.cpp index e47aaa5c..de14a95a 100644 --- a/source/DiskImageHelper.cpp +++ b/source/DiskImageHelper.cpp @@ -56,6 +56,7 @@ ImageInfo::ImageInfo() pImageBuffer = NULL; pTrackMap = NULL; optimalBitTiming = 0; + maxNibblesPerTrack = 0; } /* DO logical order 0 1 2 3 4 5 6 7 8 9 A B C D E F */ @@ -123,11 +124,12 @@ bool CImageBase::WriteTrack(ImageInfo* pImageInfo, const int nTrack, LPBYTE pTra return false; int nLen = gzwrite(hGZFile, pImageInfo->pImageBuffer, pImageInfo->uImageSize); + int nRes = gzclose(hGZFile); // close before returning (due to error) to avoid resource leak + hGZFile = NULL; + if (nLen != pImageInfo->uImageSize) return false; - int nRes = gzclose(hGZFile); - hGZFile = NULL; if (nRes != Z_OK) return false; } @@ -244,11 +246,12 @@ bool CImageBase::WriteBlock(ImageInfo* pImageInfo, const int nBlock, LPBYTE pBlo return false; int nLen = gzwrite(hGZFile, pImageInfo->pImageBuffer, pImageInfo->uImageSize); + int nRes = gzclose(hGZFile); // close before returning (due to error) to avoid resource leak + hGZFile = NULL; + if (nLen != pImageInfo->uImageSize) return false; - int nRes = gzclose(hGZFile); - hGZFile = NULL; if (nRes != Z_OK) return false; } @@ -1398,11 +1401,12 @@ ImageError_e CImageHelperBase::CheckGZipFile(LPCTSTR pszImageFilename, ImageInfo pImageInfo->pImageBuffer = new BYTE[MAX_UNCOMPRESSED_SIZE]; int nLen = gzread(hGZFile, pImageInfo->pImageBuffer, MAX_UNCOMPRESSED_SIZE); + int nRes = gzclose(hGZFile); // close before returning (due to error) to avoid resource leak + hGZFile = NULL; + if (nLen < 0 || nLen == MAX_UNCOMPRESSED_SIZE) return eIMAGE_ERROR_BAD_SIZE; - int nRes = gzclose(hGZFile); - hGZFile = NULL; if (nRes != Z_OK) return eIMAGE_ERROR_GZ; diff --git a/source/Memory.cpp b/source/Memory.cpp index 20aadb03..bf4c96a8 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -1836,8 +1836,8 @@ void MemReset() for( int i = 0; i < 256; i++ ) { clock = getRandomTime(); - random[ (i+0) & 0xFF ] ^= (clock >> 0) & 0xFF; - random[ (i+1) & 0xFF ] ^= (clock >> 11) & 0xFF; + random[ (i+0) & 0xFF ] = (clock >> 0) & 0xFF; + random[ (i+1) & 0xFF ] = (clock >> 11) & 0xFF; } memcpy( &memmain[ iByte ], random, 256 ); diff --git a/test/TestDebugger/TestDebugger.cpp b/test/TestDebugger/TestDebugger.cpp index c5ecb101..beb04df7 100644 --- a/test/TestDebugger/TestDebugger.cpp +++ b/test/TestDebugger/TestDebugger.cpp @@ -239,7 +239,7 @@ int GH445_test_jmp(BYTE op) const WORD target16 = 0x1234; - int target0, target1, target2; + int target0=0, target1=0, target2=0; if (op == OPCODE_JMP_A) { target0 = NO_6502_TARGET; @@ -262,6 +262,10 @@ int GH445_test_jmp(BYTE op) mem[target0] = target2 & 0xff; mem[target1] = (target2>>8) & 0xff; } + else + { + _ASSERT(0); + } mem[regs.pc] = op; mem[(regs.pc+1)&0xFFFF] = (BYTE) (target16&0xff); @@ -542,7 +546,7 @@ int GH451_test_jmp(BYTE op) const WORD target16 = 0x1234; - int target0, target1; + int target0=0, target1=0; if (op == OPCODE_JMP_A) { target0 = NO_6502_TARGET; @@ -558,6 +562,10 @@ int GH451_test_jmp(BYTE op) target0 = (target16+regs.x)&0xffff; target1 = (target16+regs.x+1)&0xffff; } + else + { + _ASSERT(0); + } mem[regs.pc] = op; mem[(regs.pc+1)&0xFFFF] = (BYTE) (target16&0xff);