Browse Source

[internal] rename the if_not_assert() macro to a more explicit if_assert_fails()

* Also add a new if_assert_succeeds() macro.
master
Pete Batard 2 days ago
parent
commit
c93793092a
No known key found for this signature in database GPG Key ID: 38E0CF5E69EDD671
  1. 2
      src/badblocks.c
  2. 12
      src/dev.c
  3. 6
      src/drive.c
  4. 30
      src/format.c
  5. 4
      src/process.c
  6. 10
      src/registry.h
  7. 4
      src/rufus.c
  8. 3
      src/rufus.h
  9. 10
      src/rufus.rc
  10. 8
      src/stdfn.c
  11. 2
      src/stdio.c
  12. 2
      src/stdlg.c
  13. 2
      src/ui.c
  14. 2
      src/vhd.c
  15. 4
      src/wue.c

2
src/badblocks.c

@ -549,7 +549,7 @@ static unsigned int test_rw(HANDLE hDrive, blk64_t last_block, size_t block_size
if (memcmp(read_buffer + i * block_size,
buffer + i * block_size,
block_size)) {
if_not_assert(currently_testing * block_size < 1 * PB)
if_assert_fails(currently_testing * block_size < 1 * PB)
goto out;
// coverity[overflow_const]
bb_count += bb_output(currently_testing+i-got, CORRUPTION_ERROR);

12
src/dev.c

@ -137,7 +137,7 @@ BOOL CyclePort(int index)
DWORD size;
USB_CYCLE_PORT_PARAMS cycle_port;
if_not_assert(index < MAX_DRIVES)
if_assert_fails(index < MAX_DRIVES)
return -1;
// Wait at least 10 secs between resets
if (GetTickCount64() < LastReset + 10000ULL) {
@ -191,7 +191,7 @@ int CycleDevice(int index)
SP_DEVINFO_DATA dev_info_data;
SP_PROPCHANGE_PARAMS propchange_params;
if_not_assert(index < MAX_DRIVES)
if_assert_fails(index < MAX_DRIVES)
return ERROR_INVALID_DRIVE;
if ((index < 0) || (safe_strlen(rufus_drive[index].id) < 8))
return ERROR_INVALID_PARAMETER;
@ -585,9 +585,9 @@ BOOL GetDevices(DWORD devnum)
// Better safe than sorry. And yeah, we could have used arrays of
// arrays to avoid this, but it's more readable this way.
if_not_assert((uasp_start > 0) && (uasp_start < ARRAYSIZE(usbstor_name)))
if_assert_fails((uasp_start > 0) && (uasp_start < ARRAYSIZE(usbstor_name)))
goto out;
if_not_assert((card_start > 0) && (card_start < ARRAYSIZE(genstor_name)))
if_assert_fails((card_start > 0) && (card_start < ARRAYSIZE(genstor_name)))
goto out;
devid_list = NULL;
@ -675,7 +675,7 @@ BOOL GetDevices(DWORD devnum)
}
// Also test for "_SD&" instead of "_SD_" and so on to allow for devices like
// "SCSI\DiskRicoh_Storage_SD&REV_3.0" to be detected.
if_not_assert(strlen(scsi_card_name_copy) > 1)
if_assert_fails(strlen(scsi_card_name_copy) > 1)
continue;
scsi_card_name_copy[strlen(scsi_card_name_copy) - 1] = '&';
if (safe_strstr(buffer, scsi_card_name_copy) != NULL) {
@ -1007,7 +1007,7 @@ BOOL GetDevices(DWORD devnum)
rufus_drive[num_drives].display_name = safe_strdup(display_name);
rufus_drive[num_drives].label = safe_strdup(label);
rufus_drive[num_drives].size = drive_size;
if_not_assert(rufus_drive[num_drives].size != 0)
if_assert_fails(rufus_drive[num_drives].size != 0)
break;
if (hub_path != NULL) {
rufus_drive[num_drives].hub = safe_strdup(hub_path);

6
src/drive.c

@ -279,11 +279,11 @@ char* GetLogicalName(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bKeepTrail
// Sanity checks
len = safe_strlen(volume_name);
if_not_assert(len > 4)
if_assert_fails(len > 4)
continue;
if_not_assert(safe_strnicmp(volume_name, volume_start, 4) == 0)
if_assert_fails(safe_strnicmp(volume_name, volume_start, 4) == 0)
continue;
if_not_assert(volume_name[len - 1] == '\\')
if_assert_fails(volume_name[len - 1] == '\\')
continue;
drive_type = GetDriveTypeA(volume_name);

30
src/format.c

@ -116,7 +116,7 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command,
if (IS_ERROR(ErrorStatus))
return FALSE;
if_not_assert((actual_fs_type >= 0) && (actual_fs_type < FS_MAX))
if_assert_fails((actual_fs_type >= 0) && (actual_fs_type < FS_MAX))
return FALSE;
switch(Command) {
@ -1098,9 +1098,9 @@ static int sector_write(int fd, const void* _buf, unsigned int count)
if (sec_size == 0)
sec_size = 512;
if_not_assert(sec_size <= 64 * KB)
if_assert_fails(sec_size <= 64 * KB)
return -1;
if_not_assert(count <= 1 * GB)
if_assert_fails(count <= 1 * GB)
return -1;
// If we are on a sector boundary and count is multiple of the
@ -1110,7 +1110,7 @@ static int sector_write(int fd, const void* _buf, unsigned int count)
// If we have an existing partial sector, fill and write it
if (sec_buf_pos > 0) {
if_not_assert(sec_size >= sec_buf_pos)
if_assert_fails(sec_size >= sec_buf_pos)
return -1;
fill_size = min(sec_size - sec_buf_pos, count);
memcpy(&sec_buf[sec_buf_pos], buf, fill_size);
@ -1133,13 +1133,13 @@ static int sector_write(int fd, const void* _buf, unsigned int count)
// Detect overflows
// coverity[overflow]
int v = fill_size + written;
if_not_assert(v >= fill_size)
if_assert_fails(v >= fill_size)
return -1;
else
return v;
}
sec_buf_pos = count - fill_size - written;
if_not_assert(sec_buf_pos < sec_size)
if_assert_fails(sec_buf_pos < sec_size)
return -1;
// Keep leftover bytes, if any, in the sector buffer
@ -1183,7 +1183,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
uprintf("Could not allocate disk zeroing buffer");
goto out;
}
if_not_assert((uintptr_t)buffer % SelectedDrive.SectorSize == 0)
if_assert_fails((uintptr_t)buffer % SelectedDrive.SectorSize == 0)
goto out;
// Clear buffer
@ -1196,7 +1196,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
uprintf("Could not allocate disk comparison buffer");
goto out;
}
if_not_assert((uintptr_t)cmp_buffer % SelectedDrive.SectorSize == 0)
if_assert_fails((uintptr_t)cmp_buffer % SelectedDrive.SectorSize == 0)
goto out;
}
@ -1294,7 +1294,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
uprintf("Could not allocate disk write buffer");
goto out;
}
if_not_assert((uintptr_t)sec_buf% SelectedDrive.SectorSize == 0)
if_assert_fails((uintptr_t)sec_buf% SelectedDrive.SectorSize == 0)
goto out;
sec_buf_pos = 0;
update_progress(0);
@ -1318,7 +1318,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
goto out;
}
} else {
if_not_assert(img_report.compression_type != IMG_COMPRESSION_FFU)
if_assert_fails(img_report.compression_type != IMG_COMPRESSION_FFU)
goto out;
// VHD/VHDX require mounting the image first
if (img_report.compression_type == IMG_COMPRESSION_VHD ||
@ -1345,7 +1345,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
uprintf("Could not allocate disk write buffer");
goto out;
}
if_not_assert((uintptr_t)buffer% SelectedDrive.SectorSize == 0)
if_assert_fails((uintptr_t)buffer% SelectedDrive.SectorSize == 0)
goto out;
// Start the initial read
@ -1372,7 +1372,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
// 2. WriteFile fails unless the size is a multiple of sector size
if (read_size[read_bufnum] % SelectedDrive.SectorSize != 0) {
if_not_assert(CEILING_ALIGN(read_size[read_bufnum], SelectedDrive.SectorSize) <= buf_size)
if_assert_fails(CEILING_ALIGN(read_size[read_bufnum], SelectedDrive.SectorSize) <= buf_size)
goto out;
read_size[read_bufnum] = CEILING_ALIGN(read_size[read_bufnum], SelectedDrive.SectorSize);
}
@ -1668,7 +1668,7 @@ DWORD WINAPI FormatThread(void* param)
if (img_report.compression_type == IMG_COMPRESSION_FFU) {
char cmd[MAX_PATH + 128], *physical = NULL;
// Should have been filtered out beforehand
if_not_assert(has_ffu_support)
if_assert_fails(has_ffu_support)
goto out;
safe_unlockclose(hPhysicalDrive);
physical = GetPhysicalName(SelectedDrive.DeviceNumber);
@ -1857,7 +1857,7 @@ DWORD WINAPI FormatThread(void* param)
// All good
} else if (target_type == TT_UEFI) {
// For once, no need to do anything - just check our sanity
if_not_assert((boot_type == BT_IMAGE) && IS_EFI_BOOTABLE(img_report) && (fs_type <= FS_NTFS)) {
if_assert_fails((boot_type == BT_IMAGE) && IS_EFI_BOOTABLE(img_report) && (fs_type <= FS_NTFS)) {
ErrorStatus = RUFUS_ERROR(ERROR_INSTALL_FAILURE);
goto out;
}
@ -1932,7 +1932,7 @@ DWORD WINAPI FormatThread(void* param)
ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_PATCH));
}
} else {
if_not_assert(!img_report.is_windows_img)
if_assert_fails(!img_report.is_windows_img)
goto out;
if (!ExtractISO(image_path, drive_name, FALSE)) {
if (!IS_ERROR(ErrorStatus))

4
src/process.c

@ -449,7 +449,7 @@ static DWORD WINAPI SearchProcessThread(LPVOID param)
// Work on our own copy of the handle names so we don't have to hold the
// mutex for string comparison. Update only if the version has changed.
if (blocking_process.nVersion[0] != blocking_process.nVersion[1]) {
if_not_assert(blocking_process.wHandleName != NULL && blocking_process.nHandles != 0) {
if_assert_fails(blocking_process.wHandleName != NULL && blocking_process.nHandles != 0) {
ReleaseMutex(hLock);
goto out;
}
@ -883,7 +883,7 @@ BYTE GetProcessSearch(uint32_t timeout, uint8_t access_mask, BOOL bIgnoreStalePr
return 0;
}
if_not_assert(blocking_process.hLock != NULL)
if_assert_fails(blocking_process.hLock != NULL)
return 0;
retry:

10
src/registry.h

@ -37,9 +37,9 @@ static __inline BOOL DeleteRegistryKey(HKEY key_root, const char* key_name)
HKEY hSoftware = NULL;
LONG s;
if_not_assert(key_root == REGKEY_HKCU)
if_assert_fails(key_root == REGKEY_HKCU)
return FALSE;
if_not_assert(key_name != NULL)
if_assert_fails(key_name != NULL)
return FALSE;
if (RegOpenKeyExA(key_root, "SOFTWARE", 0, KEY_READ|KEY_CREATE_SUB_KEY, &hSoftware) != ERROR_SUCCESS)
@ -133,12 +133,12 @@ static __inline BOOL _SetRegistryKey(HKEY key_root, const char* key_name, DWORD
HKEY hRoot = NULL, hApp = NULL;
DWORD dwDisp, dwType = reg_type;
if_not_assert(key_name != NULL)
if_assert_fails(key_name != NULL)
return FALSE;
if_not_assert(key_root == REGKEY_HKCU)
if_assert_fails(key_root == REGKEY_HKCU)
return FALSE;
// Validate that we are always dealing with a short key
if_not_assert(strchr(key_name, '\\') == NULL)
if_assert_fails(strchr(key_name, '\\') == NULL)
return FALSE;
if (RegOpenKeyExA(key_root, NULL, 0, KEY_READ|KEY_CREATE_SUB_KEY, &hRoot) != ERROR_SUCCESS) {

4
src/rufus.c

@ -1154,7 +1154,7 @@ static void DisplayISOProps(void)
// Insert the image name into the Boot selection dropdown and (re)populate the Image option dropdown
static void UpdateImage(BOOL update_image_option_only)
{
if_not_assert(image_index != 0)
if_assert_fails(image_index != 0)
return;
if (!update_image_option_only) {
@ -1520,7 +1520,7 @@ static DWORD WINAPI BootCheckThread(LPVOID param)
}
if (boot_type == BT_IMAGE) {
if_not_assert(image_path != NULL)
if_assert_fails(image_path != NULL)
goto out;
if ((size_check) && (img_report.projected_size > (uint64_t)SelectedDrive.DiskSize)) {
// This ISO image is too big for the selected target

3
src/rufus.h

@ -205,7 +205,8 @@ static __inline void static_repchr(char* p, char s, char r) {
}
#define to_unix_path(str) static_repchr(str, '\\', '/')
#define to_windows_path(str) static_repchr(str, '/', '\\')
#define if_not_assert(cond) assert(cond); if (!(cond))
#define if_assert_fails(cond) assert(cond); if (!(cond))
#define if_assert_succeeds(cond) assert(cond); if ((cond))
extern void uprintf(const char *format, ...);
extern void uprintfs(const char *str);

10
src/rufus.rc

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 4.10.2267"
CAPTION "Rufus 4.10.2268"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -407,8 +407,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,10,2267,0
PRODUCTVERSION 4,10,2267,0
FILEVERSION 4,10,2268,0
PRODUCTVERSION 4,10,2268,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -426,13 +426,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.10.2267"
VALUE "FileVersion", "4.10.2268"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2025 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.10.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.10.2267"
VALUE "ProductVersion", "4.10.2268"
END
END
BLOCK "VarFileInfo"

8
src/stdfn.c

@ -82,7 +82,7 @@ BOOL htab_create(uint32_t nel, htab_table* htab)
if (htab == NULL) {
return FALSE;
}
if_not_assert(htab->table == NULL) {
if_assert_fails(htab->table == NULL) {
uprintf("WARNING: htab_create() was called with a non empty table");
return FALSE;
}
@ -198,7 +198,7 @@ uint32_t htab_hash(char* str, htab_table* htab)
// Not found => New entry
// If the table is full return an error
if_not_assert(htab->filled < htab->size) {
if_assert_fails(htab->filled < htab->size) {
uprintf("Hash table is full (%d entries)", htab->size);
return 0;
}
@ -1216,7 +1216,7 @@ BOOL MountRegistryHive(const HKEY key, const char* pszHiveName, const char* pszH
LSTATUS status;
HANDLE token = INVALID_HANDLE_VALUE;
if_not_assert((key == HKEY_LOCAL_MACHINE) || (key == HKEY_USERS))
if_assert_fails((key == HKEY_LOCAL_MACHINE) || (key == HKEY_USERS))
return FALSE;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token)) {
@ -1248,7 +1248,7 @@ BOOL UnmountRegistryHive(const HKEY key, const char* pszHiveName)
{
LSTATUS status;
if_not_assert((key == HKEY_LOCAL_MACHINE) || (key == HKEY_USERS))
if_assert_fails((key == HKEY_LOCAL_MACHINE) || (key == HKEY_USERS))
return FALSE;
status = RegUnLoadKeyA(key, pszHiveName);

2
src/stdio.c

@ -924,7 +924,7 @@ uint32_t ResolveDllAddress(dll_resolver_t* resolver)
// NB: SymLoadModuleEx() does not load a PDB unless the file has an explicit '.pdb' extension
base_address = pfSymLoadModuleEx(hRufus, NULL, path, NULL, DEFAULT_BASE_ADDRESS, 0, NULL, 0);
if_not_assert(base_address == DEFAULT_BASE_ADDRESS)
if_assert_fails(base_address == DEFAULT_BASE_ADDRESS)
goto out;
// On Windows 11 ARM64 the following call will return *TWO* different addresses for the same
// call, because most Windows DLL's are ARM64X, which means that they are an unholy union of

2
src/stdlg.c

@ -604,7 +604,7 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP
return (INT_PTR)TRUE;
case IDC_MORE_INFO:
if (notification_more_info != NULL) {
if_not_assert(notification_more_info->callback != NULL)
if_assert_fails(notification_more_info->callback != NULL)
return (INT_PTR)FALSE;
if (notification_more_info->id == MORE_INFO_URL) {
ShellExecuteA(hDlg, "open", notification_more_info->url, NULL, NULL, SW_SHOWNORMAL);

2
src/ui.c

@ -579,7 +579,7 @@ void SetSectionHeaders(HWND hDlg, HFONT* hFont)
memset(wtmp, 0, sizeof(wtmp));
GetWindowTextW(hCtrl, wtmp, ARRAYSIZE(wtmp) - 4);
wlen = wcslen(wtmp);
if_not_assert(wlen < ARRAYSIZE(wtmp) - 2)
if_assert_fails(wlen < ARRAYSIZE(wtmp) - 2)
break;
wtmp[wlen++] = L' ';
wtmp[wlen++] = L' ';

2
src/vhd.c

@ -478,7 +478,7 @@ static DWORD WINAPI VhdSaveImageThread(void* param)
OVERLAPPED overlapped = { 0 };
DWORD r = ERROR_NOT_FOUND, flags;
if_not_assert(img_save->Type == VIRTUAL_STORAGE_TYPE_DEVICE_VHD ||
if_assert_fails(img_save->Type == VIRTUAL_STORAGE_TYPE_DEVICE_VHD ||
img_save->Type == VIRTUAL_STORAGE_TYPE_DEVICE_VHDX)
return ERROR_INVALID_PARAMETER;

4
src/wue.c

@ -969,7 +969,7 @@ BOOL ApplyWindowsCustomization(char drive_letter, int flags)
// If we have a windowsPE section, copy the answer files to the root of boot.wim as
// Autounattend.xml. This also results in that file being automatically copied over
// to %WINDIR%\Panther\unattend.xml for later passes processing.
if_not_assert(update_boot_wim)
if_assert_fails(update_boot_wim)
goto out;
wuc[wuc_index].op = WIMLIB_UPDATE_OP_ADD;
wuc[wuc_index].add.fs_source_path = utf8_to_wchar(unattend_xml_path);
@ -1003,7 +1003,7 @@ BOOL ApplyWindowsCustomization(char drive_letter, int flags)
StrArray files;
char tmp_dir2[MAX_PATH], *rep;
const char* efi_ex_path = "Windows\\Boot\\EFI_EX";
if_not_assert(update_boot_wim)
if_assert_fails(update_boot_wim)
goto out;
if (GetTempDirNameU(temp_dir, APPLICATION_NAME, 0, tmp_dir[1]) == 0) {
uprintf("WARNING: Could not create temp dir for 2023 signed UEFI bootloaders");

Loading…
Cancel
Save