From 5170706695dae32d5c0f33c11ff52d77c0a76b44 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 4 Jan 2017 17:23:53 +0000 Subject: [PATCH] [misc] fix coverity warnings --- _coverity.cmd | 3 +++ src/dev.c | 5 +++-- src/format.c | 17 +++++++++++++---- src/rufus.rc | 10 +++++----- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/_coverity.cmd b/_coverity.cmd index c55d133a..37a6622a 100644 --- a/_coverity.cmd +++ b/_coverity.cmd @@ -5,6 +5,9 @@ set PWD=%~dp0 rmdir cov-int /s /q >NUL 2>NUL del cov-int.zip >NUL 2>NUL mkdir cov-int +rem *** for when/if Coverity manage to clean their act +rem cov-build --dir cov-int msbuild rufus.sln /p:Configuration=Release,Platform=x86_32 /maxcpucount +rem cov-build --dir cov-int C:\msys64\usr\bin\bash -cl "export PATH=/mingw32/bin:$PATH; cd /c/rufus; ./configure --build=i686-w64-mingw32 --host=i686-w64-mingw32 --disable-debug; make -j4" cov-build --dir cov-int wdk_build.cmd rem *** zip script by Peter Mortensen - http://superuser.com/a/111266/286681 echo Set objArgs = WScript.Arguments> zip.vbs diff --git a/src/dev.c b/src/dev.c index 8c23bb87..3c37433a 100644 --- a/src/dev.c +++ b/src/dev.c @@ -227,8 +227,9 @@ BOOL GetOpticalMedia(IMG_SAVE* img_save) buffer = malloc(2048); if ((buffer != NULL) && (SetFilePointerEx(hDrive, li, NULL, FILE_BEGIN)) && ReadFile(hDrive, buffer, 2048, &size, NULL) && (size == 2048)) { - safe_strcpy(label, sizeof(label), (char*)&buffer[0x28]); - for (k = safe_strlen(label) - 1; (k >= 0) && (label[k] == 0x20); k--) + memcpy(label, &buffer[0x28], sizeof(label) - 1); + label[sizeof(label) - 1] = 0; + for (k = strlen(label) - 1; (k >= 0) && (label[k] == 0x20); k--) label[k] = 0; img_save->Label = label; } diff --git a/src/format.c b/src/format.c index fb682b11..213627cc 100644 --- a/src/format.c +++ b/src/format.c @@ -1216,7 +1216,10 @@ static BOOL SetupWinPE(char drive_letter) uprintf("Could not read file %s: %s\n", dst, WindowsErrorString()); goto out; } - SetFilePointerEx(handle, liZero, NULL, FILE_BEGIN); + if (!SetFilePointerEx(handle, liZero, NULL, FILE_BEGIN)) { + uprintf("Could not rewind file %s: %s\n", dst, WindowsErrorString()); + goto out; + } // Patch setupldr.bin uprintf("Patching file %s\n", dst); @@ -1553,13 +1556,16 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, HANDLE hSourceImage) if ((s) && (wSize == rSize)) break; if (s) - uprintf("write error: Wrote %d bytes, expected %d bytes\n", wSize, rSize); + uprintf("write error: Wrote %d bytes, expected %d bytes", wSize, rSize); else uprintf("write error: %s", WindowsErrorString()); if (i < WRITE_RETRIES - 1) { li.QuadPart = wb; - SetFilePointerEx(hPhysicalDrive, li, NULL, FILE_BEGIN); uprintf(" RETRYING...\n"); + if (!SetFilePointerEx(hPhysicalDrive, li, NULL, FILE_BEGIN)) { + uprintf("write error: could not reset position - %s", WindowsErrorString()); + goto out; + } } else { FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_WRITE_FAULT; goto out; @@ -2136,8 +2142,11 @@ DWORD WINAPI SaveImageThread(void* param) uprintf("write error: %s", WindowsErrorString()); if (i < WRITE_RETRIES-1) { li.QuadPart = wb; - SetFilePointerEx(hDestImage, li, NULL, FILE_BEGIN); uprintf(" RETRYING...\n"); + if (!SetFilePointerEx(hDestImage, li, NULL, FILE_BEGIN)) { + uprintf("write error: could not reset position - %s", WindowsErrorString()); + goto out; + } } else { FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; goto out; diff --git a/src/rufus.rc b/src/rufus.rc index 871b4579..a3005ab8 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 242, 376 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 2.12.1014" +CAPTION "Rufus 2.12.1015" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -334,8 +334,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,12,1014,0 - PRODUCTVERSION 2,12,1014,0 + FILEVERSION 2,12,1015,0 + PRODUCTVERSION 2,12,1015,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -352,13 +352,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.12.1014" + VALUE "FileVersion", "2.12.1015" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.12.1014" + VALUE "ProductVersion", "2.12.1015" END END BLOCK "VarFileInfo"