1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[misc] fix VS2012 Code Analysis warnings

* Only for files that aren't part of external dependencies
* Also update copyright date
This commit is contained in:
Pete Batard 2013-01-09 21:54:28 +00:00
parent ae43dfd721
commit c4cb9d03c1
12 changed files with 76 additions and 38 deletions

View file

@ -7,7 +7,7 @@
*
* Copyright 1995, 1996, 1997, 1998, 1999 by Theodore Ts'o
* Copyright 1999 by David Beattie
* Copyright 2011-2012 by Pete Batard
* Copyright 2011-2013 by Pete Batard
*
* This file is based on the minix file system programs fsck and mkfs
* written and copyrighted by Linus Torvalds <Linus.Torvalds@cs.helsinki.fi>
@ -121,6 +121,7 @@ static errcode_t bb_u64_list_add(bb_u64_list bb, uint64_t blk)
bb->size -= 100;
return BB_ET_NO_MEMORY;
}
memset(&bb->list[bb->size-100], 0, 100 * sizeof(uint64_t));
}
/*

View file

@ -2,7 +2,7 @@
* Rufus: The Reliable USB Formatting Utility
* DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll
* (MS WinME DOS) or from the embedded FreeDOS resource files
* Copyright (c) 2011-2012 Pete Batard <pete@akeo.ie>
* Copyright (c) 2011-2013 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -178,7 +178,10 @@ static BOOL Patch_COMMAND_COM(HANDLE hFile)
return FALSE;
}
SetFilePointer(hFile, 0x650c, NULL, FILE_BEGIN);
ReadFile(hFile, data, size, &size, NULL);
if (!ReadFile(hFile, data, size, &size, NULL)) {
uprintf(" could not read data\n");
return FALSE;
}
if (memcmp(data, expected, sizeof(expected)) != 0) {
uprintf(" unexpected binary data\n");
return FALSE;
@ -202,7 +205,10 @@ static BOOL Patch_IO_SYS(HANDLE hFile)
return FALSE;
}
SetFilePointer(hFile, 0x3a8, NULL, FILE_BEGIN);
ReadFile(hFile, data, size, &size, NULL);
if (!ReadFile(hFile, data, size, &size, NULL)) {
uprintf(" could not read data\n");
return FALSE;
}
if (memcmp(data, expected, sizeof(expected)) != 0) {
uprintf(" unexpected binary data\n");
return FALSE;
@ -307,6 +313,7 @@ static BOOL ExtractMSDOS(const char* path)
int i, j;
BOOL r = TRUE;
HMODULE hDLL;
HGLOBAL hRes;
HRSRC hDiskImage;
char locale_path[MAX_PATH];
char* extractlist[] = { "MSDOS SYS", "COMMAND COM", "IO SYS", "MODE COM",
@ -331,8 +338,10 @@ static BOOL ExtractMSDOS(const char* path)
FreeLibrary(hDLL);
return FALSE;
}
DiskImage = (BYTE*)LockResource(LoadResource(hDLL, hDiskImage));
if (DiskImage == NULL) {
hRes = LoadResource(hDLL, hDiskImage);
if (hRes != NULL)
DiskImage = (BYTE*)LockResource(hRes);
if ((hRes == NULL) || (DiskImage == NULL) ){
uprintf("Unable to access disk image in %s: %s\n", dllname, WindowsErrorString());
FreeLibrary(hDLL);
return FALSE;

View file

@ -1,7 +1,7 @@
/*
* Rufus: The Reliable USB Formatting Utility
* DOS keyboard locale setup
* Copyright (c) 2011-2012 Pete Batard <pete@akeo.ie>
* Copyright (c) 2011-2013 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -410,7 +410,10 @@ static const char* get_kb(void)
// need an KLID which GetKeyboardLayoutNameA() does return ...but only as a
// string of an hex value...
GetKeyboardLayoutNameA(kbid_str);
sscanf(kbid_str, "%x", &kbid);
if (sscanf(kbid_str, "%x", &kbid) == 0) {
uprintf("Could not scan keyboard layout name - falling back to US as default\n");
kbid = 0x00000409;
}
uprintf("Windows KBID 0x%08x\n", kbid);
for (pass=0; pass<3; pass++) {

View file

@ -180,7 +180,7 @@ BOOL GetDriveLabel(DWORD DriveIndex, char* letter, char** label)
strncpy(VolumeLabel, AutorunLabel, sizeof(VolumeLabel));
safe_free(AutorunLabel);
*label = VolumeLabel;
} else if (GetVolumeInformationW(wDrivePath, wVolumeLabel, sizeof(wVolumeLabel),
} else if (GetVolumeInformationW(wDrivePath, wVolumeLabel, ARRAYSIZE(wVolumeLabel),
NULL, NULL, NULL, NULL, 0) && *wVolumeLabel) {
wchar_to_utf8_no_alloc(wVolumeLabel, VolumeLabel, sizeof(VolumeLabel));
*label = VolumeLabel;

View file

@ -1,9 +1,9 @@
/*
* Rufus: The Reliable USB Formatting Utility
* ISO file extraction
* Copyright (c) 2011-2012 Pete Batard <pete@akeo.ie>
* Copyright (c) 2011-2013 Pete Batard <pete@akeo.ie>
* Based on libcdio's iso & udf samples:
* Copyright (c) 2003-2011 Rocky Bernstein <rocky@gnu.org>
* Copyright (c) 2003-2012 Rocky Bernstein <rocky@gnu.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -185,7 +185,7 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha
uprintf("Error allocating file name\n");
goto out;
}
i_length = safe_sprintf(psz_fullpath, i_length, "%s%s/%s", psz_extract_dir, psz_path, psz_basename);
i_length = _snprintf(psz_fullpath, i_length, "%s%s/%s", psz_extract_dir, psz_path, psz_basename);
if (i_length < 0) {
goto out;
}
@ -292,7 +292,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
if ((p_iso == NULL) || (psz_path == NULL))
return 1;
i_length = safe_sprintf(psz_fullpath, sizeof(psz_fullpath), "%s%s/", psz_extract_dir, psz_path);
i_length = _snprintf(psz_fullpath, sizeof(psz_fullpath), "%s%s/", psz_extract_dir, psz_path);
if (i_length < 0)
return 1;
psz_basename = &psz_fullpath[i_length];

View file

@ -2,7 +2,7 @@
* MSAPI_UTF8: Common API calls using UTF-8 strings
* Compensating for what Microsoft should have done a long long time ago.
*
* Copyright (c) 2010-2012 Pete Batard <pete@akeo.ie>
* Copyright (c) 2010-2013 Pete Batard <pete@akeo.ie>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -27,6 +27,10 @@
#include <direct.h>
#pragma once
#if defined(_MSC_VER)
// disable VS2012 Code Analysis warnings that are intentional
#pragma warning(disable: 6387) // Don't care about bad params
#endif
#ifdef __cplusplus
extern "C" {

View file

@ -1,7 +1,7 @@
/*
* Rufus: The Reliable USB Formatting Utility
* Networking functionality (web file download, check for update, etc.)
* Copyright (c) 2012 Pete Batard <pete@akeo.ie>
* Copyright (c) 2012-2013 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -270,6 +270,7 @@ BOOL DownloadFile(const char* url, const char* file, HWND hProgressDialog)
uprintf("Unable to decode URL: %s\n", WindowsErrorString());
goto out;
}
hostname[sizeof(hostname)-1] = 0;
// Open an Internet session
for (i=5; (i>0) && (!InternetGetConnectedState(&dwFlags, 0)); i--) {
@ -476,8 +477,9 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
if ((!InternetCrackUrlA(server_url, (DWORD)safe_strlen(server_url), 0, &UrlParts)) || (!InternetGetConnectedState(&dwFlags, 0)))
goto out;
hostname[sizeof(hostname)-1] = 0;
_snprintf(agent, ARRAYSIZE(agent), APPLICATION_NAME "/%d.%d.%d.%d", rufus_version[0], rufus_version[1], rufus_version[2], rufus_version[3]);
safe_sprintf(agent, ARRAYSIZE(agent), APPLICATION_NAME "/%d.%d.%d.%d", rufus_version[0], rufus_version[1], rufus_version[2], rufus_version[3]);
hSession = InternetOpenA(agent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hSession == NULL)
goto out;

View file

@ -1,6 +1,6 @@
/*
* Rufus: The Reliable USB Formatting Utility
* Copyright © 2011-2012 Pete Batard <pete@akeo.ie>
* Copyright © 2011-2013 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -395,7 +395,7 @@ static BOOL GetDriveInfo(void)
DriveLayout->PartitionEntry[i].Mbr.BootIndicator?"Yes":"No",
DriveLayout->PartitionEntry[i].Mbr.RecognizedPartition?"Yes":"No",
DriveLayout->PartitionEntry[i].Mbr.HiddenSectors);
tmp_pos = safe_sprintf(&tmp[tmp_pos], sizeof(tmp)-tmp_pos, "Partition %d: %s (%s)\n",
tmp_pos = _snprintf(&tmp[tmp_pos], sizeof(tmp)-tmp_pos, "Partition %d: %s (%s)\n",
i+1, GetPartitionType(part_type), size_to_hr(DriveLayout->PartitionEntry[i].PartitionLength));
}
}
@ -525,7 +525,7 @@ static BOOL PopulateProperties(int ComboIndex)
{
double HumanReadableSize;
char capacity[64];
static char *suffix[] = { "KB", "MB", "GB", "TB", "PB"};
static char *suffix[] = { "B", "KB", "MB", "GB", "TB", "PB"};
char no_label[] = STR_NO_LABEL;
int i, fs;
@ -547,7 +547,7 @@ static BOOL PopulateProperties(int ComboIndex)
EnableBootOptions((fs == FS_FAT16) || (fs == FS_FAT32) || (fs == FS_NTFS));
HumanReadableSize = (double)SelectedDrive.DiskSize;
for (i=0; i<ARRAYSIZE(suffix); i++) {
for (i=1; i<ARRAYSIZE(suffix); i++) {
HumanReadableSize /= 1024.0;
if (HumanReadableSize < 512.0) {
safe_sprintf(capacity, sizeof(capacity), "%0.2f %s", HumanReadableSize, suffix[i]);
@ -751,6 +751,10 @@ static BOOL GetUSBDevices(DWORD devnum)
continue;
}
}
if (devint_detail_data == NULL) {
uprintf("SetupDiGetDeviceInterfaceDetail (dummy) - no data was allocated\n");
continue;
}
if(!SetupDiGetDeviceInterfaceDetailA(dev_info, &devint_data, devint_detail_data, size, &size, NULL)) {
uprintf("SetupDiGetDeviceInterfaceDetail (actual) failed: %s\n", WindowsErrorString());
continue;
@ -1207,7 +1211,7 @@ BOOL CALLBACK ISOProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
hISOProgressBar = GetDlgItem(hDlg, IDC_PROGRESS);
hISOFileName = GetDlgItem(hDlg, IDC_ISO_FILENAME);
// Use maximum granularity for the progress bar
SendMessage(hISOProgressBar, PBM_SETRANGE, 0, MAX_PROGRESS<<16);
SendMessage(hISOProgressBar, PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000);
return TRUE;
case UM_ISO_INIT:
iso_op_in_progress = TRUE;
@ -1450,7 +1454,7 @@ void InitDialog(HWND hDlg)
SetTaskbarProgressState(TASKBAR_NORMAL);
// Use maximum granularity for the progress bar
SendMessage(hProgress, PBM_SETRANGE, 0, MAX_PROGRESS<<16);
SendMessage(hProgress, PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000);
// Fill up the passes
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "1 Pass"));
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "2 Passes"));
@ -1902,9 +1906,9 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
GetUSBDevices(DeviceNum);
if (!IS_ERROR(FormatStatus)) {
// This is the only way to achieve instantenous progress transition to 100%
SendMessage(hProgress, PBM_SETRANGE, 0, (MAX_PROGRESS+1)<<16);
SendMessage(hProgress, PBM_SETRANGE, 0, ((MAX_PROGRESS+1)<<16) & 0xFFFF0000);
SendMessage(hProgress, PBM_SETPOS, (MAX_PROGRESS+1), 0);
SendMessage(hProgress, PBM_SETRANGE, 0, MAX_PROGRESS<<16);
SendMessage(hProgress, PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000);
SetTaskbarProgressState(TASKBAR_NOPROGRESS);
PrintStatus(0, FALSE, "DONE");
} else if (SCODE_CODE(FormatStatus) == ERROR_CANCELLED) {
@ -1931,7 +1935,11 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
*/
// If we ever need to process more than one commandline arguments, uncomment the following parts
// typedef int (CDECL *__wgetmainargs_t)(int*, wchar_t***, wchar_t***, int, int*);
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
#else
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#endif
{
// int i, argc = 0, si = 0;
// char** argv = NULL;
@ -1976,7 +1984,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
hMainInstance = hInstance;
// Initialize COM for folder selection
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
IGNORE_RETVAL(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED));
// Some dialogs have Rich Edit controls and won't display without this
if (LoadLibraryA("Riched20.dll") == NULL) {

View file

@ -1,6 +1,6 @@
/*
* Rufus: The Reliable USB Formatting Utility
* Copyright © 2011-2012 Pete Batard <pete@akeo.ie>
* Copyright © 2011-2013 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,6 +19,11 @@
#include <winioctl.h> // for DISK_GEOMETRY
#include <stdint.h>
#if defined(_MSC_VER)
// Disable some VS2012 Code Analysis warnings
#pragma warning(disable: 28159) // VS2012 wants us to use GetTickCount64(), but it's not available on XP
#endif
#pragma once
/* Program options */
@ -63,7 +68,7 @@
#define safe_strnicmp(str1, str2, count) _strnicmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2), count)
#define safe_closehandle(h) do {if (h != INVALID_HANDLE_VALUE) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
#define safe_unlockclose(h) do {if (h != INVALID_HANDLE_VALUE) {UnlockDrive(h); CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
#define safe_sprintf _snprintf
#define safe_sprintf(dst, count, ...) do {_snprintf(dst, count, __VA_ARGS__); (dst)[(count)-1] = 0; } while(0)
#define safe_strlen(str) ((((char*)str)==NULL)?0:strlen(str))
#define safe_strdup _strdup
#if defined(_MSC_VER)

View file

@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 316
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.3.0.215"
CAPTION "Rufus v1.3.0.216"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,278,50,14
@ -274,8 +274,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,3,0,215
PRODUCTVERSION 1,3,0,215
FILEVERSION 1,3,0,216
PRODUCTVERSION 1,3,0,216
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -292,13 +292,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.3.0.215"
VALUE "FileVersion", "1.3.0.216"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "(c) 2011-2012 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.3.0.215"
VALUE "ProductVersion", "1.3.0.216"
END
END
BLOCK "VarFileInfo"

View file

@ -1,7 +1,7 @@
/*
* Rufus: The Reliable USB Formatting Utility
* Standard I/O Routines (logging, status, etc.)
* Copyright (c) 2011-2012 Pete Batard <pete@akeo.ie>
* Copyright (c) 2011-2013 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -107,7 +107,7 @@ void DumpBufferHex(void *buf, size_t size)
*/
const char *WindowsErrorString(void)
{
static char err_string[256];
static char err_string[256] = {0};
DWORD size;
DWORD error_code, format_error;

View file

@ -1,9 +1,9 @@
/*
* Rufus: The Reliable USB Formatting Utility
* Standard Dialog Routines (Browse for folder, About, etc)
* Copyright © 2011-2012 Pete Batard <pete@akeo.ie>
* Copyright © 2011-2013 Pete Batard <pete@akeo.ie>
*
* Based on zadig_stdlg.c, part of libwdi: http://libwdi.sf.net
* Based on zadig_stdlg.c, part of libwdi: http://libwdi.akeo.ie
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -114,12 +114,15 @@ void StrArrayCreate(StrArray* arr, size_t initial_size)
void StrArrayAdd(StrArray* arr, const char* str)
{
char** old_table;
if ((arr == NULL) || (arr->Table == NULL))
return;
if (arr->Index == arr->Max) {
arr->Max *= 2;
old_table = arr->Table;
arr->Table = (char**)realloc(arr->Table, arr->Max*sizeof(char*));
if (arr->Table == NULL) {
free(old_table);
uprintf("Could not reallocate string array\n");
return;
}
@ -700,6 +703,7 @@ INT_PTR CALLBACK AboutCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
tr.chrg.cpMin = enl->chrg.cpMin;
tr.chrg.cpMax = enl->chrg.cpMax;
SendMessageW(enl->nmhdr.hwndFrom, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
wUrl[ARRAYSIZE(wUrl)-1] = 0;
ShellExecuteW(hDlg, L"open", wUrl, NULL, NULL, SW_SHOWNORMAL);
}
break;
@ -970,7 +974,8 @@ void DestroyAllTooltips(void)
/* Determine if a Windows is being displayed or not */
BOOL IsShown(HWND hDlg)
{
WINDOWPLACEMENT placement;
WINDOWPLACEMENT placement = {0};
placement.length = sizeof(WINDOWPLACEMENT);
if (!GetWindowPlacement(hDlg, &placement))
return FALSE;
switch (placement.showCmd) {
@ -1282,7 +1287,7 @@ INT_PTR CALLBACK NewVersionCallback(HWND hDlg, UINT message, WPARAM wParam, LPAR
update.version[0], update.version[1], update.version[2], update.version[3]);
SetWindowTextA(GetDlgItem(hDlg, IDC_LATEST_VERSION), tmp);
SetWindowTextA(GetDlgItem(hDlg, IDC_DOWNLOAD_URL), update.download_url);
SendMessage(GetDlgItem(hDlg, IDC_PROGRESS), PBM_SETRANGE, 0, MAX_PROGRESS<<16);
SendMessage(GetDlgItem(hDlg, IDC_PROGRESS), PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000);
if (update.download_url == NULL)
EnableWindow(GetDlgItem(hDlg, IDC_DOWNLOAD), FALSE);
break;
@ -1301,6 +1306,7 @@ INT_PTR CALLBACK NewVersionCallback(HWND hDlg, UINT message, WPARAM wParam, LPAR
tr.chrg.cpMin = enl->chrg.cpMin;
tr.chrg.cpMax = enl->chrg.cpMax;
SendMessageW(enl->nmhdr.hwndFrom, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
wUrl[ARRAYSIZE(wUrl)-1] = 0;
ShellExecuteW(hDlg, L"open", wUrl, NULL, NULL, SW_SHOWNORMAL);
}
break;