From edcfd43ed550b17f23f9534f4b3b5cdd7fffdefc Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Fri, 10 Mar 2017 19:07:48 +0100 Subject: [PATCH] [misc] fix multiple VS Code Analysis warnings --- src/format.c | 5 ++++- src/libcdio/driver/_cdio_stdio.c | 2 ++ src/libcdio/driver/_cdio_stream.c | 1 + src/libcdio/driver/ds.c | 2 ++ src/libcdio/driver/utf8.c | 3 +++ src/libcdio/driver/util.c | 18 ++++++++++-------- src/libcdio/iso9660/iso9660_fs.c | 9 ++++----- src/libcdio/udf/udf_fs.c | 2 +- src/parser.c | 8 ++++++-- src/rufus.h | 2 +- src/rufus.rc | 10 +++++----- src/stdlg.c | 7 +++++++ src/syslinux/win/ntfssect.c | 2 ++ 13 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/format.c b/src/format.c index fce1991b..f31d2a28 100644 --- a/src/format.c +++ b/src/format.c @@ -2,7 +2,7 @@ * Rufus: The Reliable USB Formatting Utility * Formatting function calls * Copyright © 2007-2009 Tom Thornhill/Ridgecrop - * Copyright © 2011-2016 Pete Batard + * Copyright © 2011-2017 Pete Batard * * 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 @@ -865,6 +865,9 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) AnalyzeMBR(hPhysicalDrive, "Drive"); + if (SelectedDrive.SectorSize < 512) + goto out; + // FormatEx rewrites the MBR and removes the LBA attribute of FAT16 // and FAT32 partitions - we need to correct this in the MBR buffer = (unsigned char*)_mm_malloc(SelectedDrive.SectorSize, 16); diff --git a/src/libcdio/driver/_cdio_stdio.c b/src/libcdio/driver/_cdio_stdio.c index 805cc699..1d46b156 100644 --- a/src/libcdio/driver/_cdio_stdio.c +++ b/src/libcdio/driver/_cdio_stdio.c @@ -45,6 +45,7 @@ #include #include "_cdio_stream.h" #include "_cdio_stdio.h" +#include "cdio_assert.h" /* On 32 bit platforms, fseek can only access streams of 2 GB or less. Prefer fseeko/fseeko64, that take a 64 bit offset when LFS is enabled */ @@ -265,6 +266,7 @@ cdio_stdio_new(const char pathname[]) } ud = calloc (1, sizeof (_UserData)); + cdio_assert (ud != NULL); ud->pathname = pathdup; ud->st_size = statbuf.st_size; /* let's hope it doesn't change... */ diff --git a/src/libcdio/driver/_cdio_stream.c b/src/libcdio/driver/_cdio_stream.c index 79dab947..f8da21e1 100644 --- a/src/libcdio/driver/_cdio_stream.c +++ b/src/libcdio/driver/_cdio_stream.c @@ -99,6 +99,7 @@ cdio_stream_new(void *user_data, const cdio_stream_io_functions *funcs) CdioDataSource_t *new_obj; new_obj = calloc (1, sizeof (CdioDataSource_t)); + cdio_assert (new_obj != NULL); new_obj->user_data = user_data; memcpy(&(new_obj->op), funcs, sizeof(cdio_stream_io_functions)); diff --git a/src/libcdio/driver/ds.c b/src/libcdio/driver/ds.c index cf53e548..c9abec23 100644 --- a/src/libcdio/driver/ds.c +++ b/src/libcdio/driver/ds.c @@ -85,6 +85,7 @@ _cdio_list_prepend (CdioList_t *p_list, void *p_data) cdio_assert (p_list != NULL); p_new_node = calloc (1, sizeof (CdioListNode_t)); + cdio_assert (p_new_node != NULL); p_new_node->list = p_list; p_new_node->next = p_list->begin; @@ -109,6 +110,7 @@ _cdio_list_append (CdioList_t *p_list, void *p_data) else { CdioListNode_t *p_new_node = calloc (1, sizeof (CdioListNode_t)); + cdio_assert (p_new_node != NULL); p_new_node->list = p_list; p_new_node->next = NULL; diff --git a/src/libcdio/driver/utf8.c b/src/libcdio/driver/utf8.c index b87cb029..28353d0b 100644 --- a/src/libcdio/driver/utf8.c +++ b/src/libcdio/driver/utf8.c @@ -42,6 +42,7 @@ #include #include #include +#include "cdio_assert.h" /* Windows requires some basic UTF-8 support outside of Joliet */ #if defined(_WIN32) @@ -300,6 +301,7 @@ bool cdio_charset_from_utf8(cdio_utf8_t * src, char ** dst, /* Perform byte reversal */ len = wcslen(le_dst); *dst = (char*)calloc(len+1, sizeof(wchar_t)); + cdio_assert(*dst != NULL); for (i=0; i<2*len; i++) { (*dst)[i] = ((char*)le_dst)[i+1]; (*dst)[i+1] = ((char*)le_dst)[i]; @@ -333,6 +335,7 @@ bool cdio_charset_to_utf8(const char *src, size_t src_len, cdio_utf8_t **dst, /* Perform byte reversal */ le_src = (wchar_t*)malloc(2*src_len+2); + cdio_assert(le_src != NULL); for (i=0; ifilename)+1; p_stat = calloc(1, len); + cdio_assert (p_stat != NULL); memcpy(p_stat, _root, len); p_stat->rr.psz_symlink = calloc(1, p_stat->rr.i_symlink_max); + cdio_assert (p_stat->rr.psz_symlink != NULL); memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink, p_stat->rr.i_symlink_max); return p_stat; @@ -1055,13 +1057,10 @@ _fs_iso_stat_traverse (iso9660_t *p_iso, const iso9660_stat_t *_root, iso9660_stat_t *p_stat; unsigned int len=sizeof(iso9660_stat_t) + strlen(_root->filename)+1; p_stat = calloc(1, len); - if (!p_stat) - { - cdio_warn("Couldn't calloc(1, %d)", len); - return NULL; - } + cdio_assert (p_stat != NULL); memcpy(p_stat, _root, len); p_stat->rr.psz_symlink = calloc(1, p_stat->rr.i_symlink_max); + cdio_assert (p_stat->rr.psz_symlink != NULL); memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink, p_stat->rr.i_symlink_max); return p_stat; diff --git a/src/libcdio/udf/udf_fs.c b/src/libcdio/udf/udf_fs.c index a0a39034..702268b4 100644 --- a/src/libcdio/udf/udf_fs.c +++ b/src/libcdio/udf/udf_fs.c @@ -254,8 +254,8 @@ udf_fopen(udf_dirent_t *p_udf_root, const char *psz_name) /* file position must be reset when accessing a new file */ p_udf_root->p_udf->i_position = 0; - tokenline[udf_MAX_PATHLEN-1] = '\0'; strncpy(tokenline, psz_name, udf_MAX_PATHLEN-1); + tokenline[udf_MAX_PATHLEN-1] = '\0'; psz_token = strtok(tokenline, udf_PATH_DELIMITERS); if (psz_token) { udf_dirent_t *p_udf_dirent = diff --git a/src/parser.c b/src/parser.c index 911ad642..5950a13c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Elementary Unicode compliant find/replace parser - * Copyright © 2012-2016 Pete Batard + * Copyright © 2012-2017 Pete Batard * * 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 @@ -1234,7 +1234,7 @@ out: } /* - * Replace all 'c' characters in string 'src' with the subtsring 'rep' + * Replace all 'c' characters in string 'src' with the substring 'rep' * The returned string is allocated and must be freed by the caller. */ char* replace_char(const char* src, const char c, const char* rep) @@ -1256,6 +1256,10 @@ char* replace_char(const char* src, const char c, const char* rep) for(k=0; k #if defined(_MSC_VER) -// Disable some VS2012 Code Analysis warnings +// Disable some VS Code Analysis warnings #pragma warning(disable: 4996) // Ignore deprecated (eg. GetVersionEx()), as we have to contend with XP #pragma warning(disable: 28159) // We use GetTickCount64() where possible, but it's not available on XP #pragma warning(disable: 6258) // I know what I'm using TerminateThread for diff --git a/src/rufus.rc b/src/rufus.rc index ef10c604..855a511e 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.13.1070" +CAPTION "Rufus 2.13.1071" 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,13,1070,0 - PRODUCTVERSION 2,13,1070,0 + FILEVERSION 2,13,1071,0 + PRODUCTVERSION 2,13,1071,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.13.1070" + VALUE "FileVersion", "2.13.1071" 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.13.1070" + VALUE "ProductVersion", "2.13.1071" END END BLOCK "VarFileInfo" diff --git a/src/stdlg.c b/src/stdlg.c index e240694a..b6468623 100644 --- a/src/stdlg.c +++ b/src/stdlg.c @@ -373,7 +373,14 @@ char* FileDialog(BOOL save, char* path, const ext_t* ext, DWORD options) j = _snprintf(&ext_string[j], ext_strlen-j, "%s (*.*)\r*.*\r", all_files); // Microsoft could really have picked a better delimiter! for (i=0; iHandle == NULL) || (VolumeInfo->Handle == INVALID_HANDLE_VALUE)) + return ERROR_INVALID_HANDLE; } rc = NtfsSectLoadXpFuncs(&xp_funcs);