mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[misc] fix PVS-Studio static analyzer warnings
* Surround macro params to ensure expected results * Fix copy-paste errors * Fix a potential buffer overflow in SetSectionHeaders() * Add const modifier where relevant * Use GetWindowLongPtr() everywhere * Use proper sprintf format for unsigned int * Use %s for printf-like funcs (https://www.viva64.com/en/w/v618/print/) * Closes #1464
This commit is contained in:
		
							parent
							
								
									42d1705ec4
								
							
						
					
					
						commit
						29d0fa2be3
					
				
					 10 changed files with 27 additions and 27 deletions
				
			
		|  | @ -463,7 +463,7 @@ static unsigned int test_rw(HANDLE hDrive, blk64_t last_block, size_t block_size | ||||||
| 			if (max_bb && bb_count >= max_bb) { | 			if (max_bb && bb_count >= max_bb) { | ||||||
| 				if (s_flag || v_flag) { | 				if (s_flag || v_flag) { | ||||||
| 					uprintf(abort_msg); | 					uprintf(abort_msg); | ||||||
| 					fprintf(log_fd, abort_msg); | 					fprintf(log_fd, "%s", abort_msg); | ||||||
| 					fflush(log_fd); | 					fflush(log_fd); | ||||||
| 				} | 				} | ||||||
| 				cancel_ops = -1; | 				cancel_ops = -1; | ||||||
|  | @ -511,7 +511,7 @@ static unsigned int test_rw(HANDLE hDrive, blk64_t last_block, size_t block_size | ||||||
| 			if (max_bb && bb_count >= max_bb) { | 			if (max_bb && bb_count >= max_bb) { | ||||||
| 				if (s_flag || v_flag) { | 				if (s_flag || v_flag) { | ||||||
| 					uprintf(abort_msg); | 					uprintf(abort_msg); | ||||||
| 					fprintf(log_fd, abort_msg); | 					fprintf(log_fd, "%s", abort_msg); | ||||||
| 					fflush(log_fd); | 					fflush(log_fd); | ||||||
| 				} | 				} | ||||||
| 				cancel_ops = -1; | 				cancel_ops = -1; | ||||||
|  |  | ||||||
|  | @ -250,8 +250,8 @@ static void ToValidLabel(char* Label, BOOL bFAT) | ||||||
| { | { | ||||||
| 	size_t i, j, k; | 	size_t i, j, k; | ||||||
| 	BOOL found; | 	BOOL found; | ||||||
| 	WCHAR unauthorized[] = L"*?,;:/\\|+=<>[]\""; | 	const WCHAR unauthorized[] = L"*?,;:/\\|+=<>[]\""; | ||||||
| 	WCHAR to_underscore[] = L"\t."; | 	const WCHAR to_underscore[] = L"\t."; | ||||||
| 	WCHAR *wLabel = utf8_to_wchar(Label); | 	WCHAR *wLabel = utf8_to_wchar(Label); | ||||||
| 
 | 
 | ||||||
| 	if (wLabel == NULL) | 	if (wLabel == NULL) | ||||||
|  | @ -1863,7 +1863,7 @@ DWORD WINAPI FormatThread(void* param) | ||||||
| 			if (report.bb_count) { | 			if (report.bb_count) { | ||||||
| 				bb_msg = lmprintf(MSG_011, report.bb_count, report.num_read_errors, report.num_write_errors, | 				bb_msg = lmprintf(MSG_011, report.bb_count, report.num_read_errors, report.num_write_errors, | ||||||
| 					report.num_corruption_errors); | 					report.num_corruption_errors); | ||||||
| 				fprintf(log_fd, bb_msg); | 				fprintf(log_fd, "%s", bb_msg); | ||||||
| 				GetLocalTime(<); | 				GetLocalTime(<); | ||||||
| 				fprintf(log_fd, APPLICATION_NAME " bad blocks check ended on: %04d.%02d.%02d %02d:%02d:%02d", | 				fprintf(log_fd, APPLICATION_NAME " bad blocks check ended on: %04d.%02d.%02d %02d:%02d:%02d", | ||||||
| 				lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond); | 				lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond); | ||||||
|  |  | ||||||
|  | @ -177,7 +177,7 @@ const char* error_message(errcode_t error_code) | ||||||
| 			static_sprintf(error_string, "Unknown ext2fs error %ld (EXT2_ET_BASE + %ld)", error_code, error_code - EXT2_ET_BASE); | 			static_sprintf(error_string, "Unknown ext2fs error %ld (EXT2_ET_BASE + %ld)", error_code, error_code - EXT2_ET_BASE); | ||||||
| 		} else { | 		} else { | ||||||
| 			SetLastError((FormatStatus == 0) ? (ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | (error_code & 0xFFFF)) : FormatStatus); | 			SetLastError((FormatStatus == 0) ? (ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | (error_code & 0xFFFF)) : FormatStatus); | ||||||
| 			static_sprintf(error_string, WindowsErrorString()); | 			static_sprintf(error_string, "%s", WindowsErrorString()); | ||||||
| 		} | 		} | ||||||
| 		return error_string; | 		return error_string; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -378,7 +378,7 @@ char* lmprintf(uint32_t msg_id, ...) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (format == NULL) { | 	if (format == NULL) { | ||||||
| 		safe_sprintf(buf[buf_id], LOC_MESSAGE_SIZE-1, "MSG_%03d UNTRANSLATED", msg_id - MSG_000); | 		safe_sprintf(buf[buf_id], LOC_MESSAGE_SIZE-1, "MSG_%03u UNTRANSLATED", msg_id - MSG_000); | ||||||
| 	} else { | 	} else { | ||||||
| 		if (right_to_left_mode && (msg_table != default_msg_table)) { | 		if (right_to_left_mode && (msg_table != default_msg_table)) { | ||||||
| 			if (is_rtf) { | 			if (is_rtf) { | ||||||
|  |  | ||||||
|  | @ -41,7 +41,7 @@ | ||||||
| #include "settings.h" | #include "settings.h" | ||||||
| 
 | 
 | ||||||
| /* Maximum download chunk size, in bytes */ | /* Maximum download chunk size, in bytes */ | ||||||
| #define DOWNLOAD_BUFFER_SIZE    10*KB | #define DOWNLOAD_BUFFER_SIZE    (10*KB) | ||||||
| /* Default delay between update checks (1 day) */ | /* Default delay between update checks (1 day) */ | ||||||
| #define DEFAULT_UPDATE_INTERVAL (24*3600) | #define DEFAULT_UPDATE_INTERVAL (24*3600) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/parser.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/parser.c
									
										
									
									
									
								
							|  | @ -646,7 +646,7 @@ char* get_token_data_file_indexed(const char* token, const char* filename, int i | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	wtoken = utf8_to_wchar(token); | 	wtoken = utf8_to_wchar(token); | ||||||
| 	if (wfilename == NULL) { | 	if (wtoken == NULL) { | ||||||
| 		uprintf(conversion_error, token); | 		uprintf(conversion_error, token); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
|  | @ -695,7 +695,7 @@ char* set_token_data_file(const char* token, const char* data, const char* filen | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	wtoken = utf8_to_wchar(token); | 	wtoken = utf8_to_wchar(token); | ||||||
| 	if (wfilename == NULL) { | 	if (wtoken == NULL) { | ||||||
| 		uprintf(conversion_error, token); | 		uprintf(conversion_error, token); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
|  | @ -974,7 +974,7 @@ char* insert_section_data(const char* filename, const char* section, const char* | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	wsection = utf8_to_wchar(section); | 	wsection = utf8_to_wchar(section); | ||||||
| 	if (wfilename == NULL) { | 	if (wsection == NULL) { | ||||||
| 		uprintf(conversion_error, section); | 		uprintf(conversion_error, section); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
|  | @ -1110,7 +1110,7 @@ char* replace_in_token_data(const char* filename, const char* token, const char* | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	wtoken = utf8_to_wchar(token); | 	wtoken = utf8_to_wchar(token); | ||||||
| 	if (wfilename == NULL) { | 	if (wtoken == NULL) { | ||||||
| 		uprintf(conversion_error, token); | 		uprintf(conversion_error, token); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
|  | @ -1120,7 +1120,7 @@ char* replace_in_token_data(const char* filename, const char* token, const char* | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	wrep = utf8_to_wchar(rep); | 	wrep = utf8_to_wchar(rep); | ||||||
| 	if (wsrc == NULL) { | 	if (wrep == NULL) { | ||||||
| 		uprintf(conversion_error, rep); | 		uprintf(conversion_error, rep); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -138,7 +138,7 @@ const char* flash_type[BADLOCKS_PATTERN_TYPES] = { "SLC", "MLC", "TLC" }; | ||||||
| static void SetClusterSizeLabels(void) | static void SetClusterSizeLabels(void) | ||||||
| { | { | ||||||
| 	unsigned int i, j, msg_id; | 	unsigned int i, j, msg_id; | ||||||
| 	safe_sprintf(ClusterSizeLabel[0], 64, lmprintf(MSG_029)); | 	safe_sprintf(ClusterSizeLabel[0], 64, "%s", lmprintf(MSG_029)); | ||||||
| 	for (i=512, j=1, msg_id=MSG_026; j<MAX_CLUSTER_SIZES; i<<=1, j++) { | 	for (i=512, j=1, msg_id=MSG_026; j<MAX_CLUSTER_SIZES; i<<=1, j++) { | ||||||
| 		if (i > 8192) { | 		if (i > 8192) { | ||||||
| 			i /= 1024; | 			i /= 1024; | ||||||
|  | @ -885,7 +885,7 @@ static BOOL PopulateProperties(void) | ||||||
| 	EnableControls(TRUE, FALSE); | 	EnableControls(TRUE, FALSE); | ||||||
| 
 | 
 | ||||||
| 	// Set a proposed label according to the size (eg: "256MB", "8GB")
 | 	// Set a proposed label according to the size (eg: "256MB", "8GB")
 | ||||||
| 	static_sprintf(SelectedDrive.proposed_label, | 	static_sprintf(SelectedDrive.proposed_label, "%s", | ||||||
| 		SizeToHumanReadable(SelectedDrive.DiskSize, FALSE, use_fake_units)); | 		SizeToHumanReadable(SelectedDrive.DiskSize, FALSE, use_fake_units)); | ||||||
| 
 | 
 | ||||||
| 	// Add a tooltip (with the size of the device in parenthesis)
 | 	// Add a tooltip (with the size of the device in parenthesis)
 | ||||||
|  |  | ||||||
|  | @ -656,8 +656,8 @@ static __inline HMODULE GetLibraryHandle(char* szLibraryName) { | ||||||
| 	if ((pf##proc == NULL) && (NT_SUCCESS(status))) status = STATUS_NOT_IMPLEMENTED; } while(0) | 	if ((pf##proc == NULL) && (NT_SUCCESS(status))) status = STATUS_NOT_IMPLEMENTED; } while(0) | ||||||
| 
 | 
 | ||||||
| /* Custom application errors */ | /* Custom application errors */ | ||||||
| #define FAC(f)                         (f<<16) | #define FAC(f)                         ((f)<<16) | ||||||
| #define APPERR(err)                    (APPLICATION_ERROR_MASK|err) | #define APPERR(err)                    (APPLICATION_ERROR_MASK|(err)) | ||||||
| #define ERROR_INCOMPATIBLE_FS          0x1201 | #define ERROR_INCOMPATIBLE_FS          0x1201 | ||||||
| #define ERROR_CANT_QUICK_FORMAT        0x1202 | #define ERROR_CANT_QUICK_FORMAT        0x1202 | ||||||
| #define ERROR_INVALID_CLUSTER_SIZE     0x1203 | #define ERROR_INVALID_CLUSTER_SIZE     0x1203 | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | ||||||
| IDD_DIALOG DIALOGEX 12, 12, 232, 326 | IDD_DIALOG DIALOGEX 12, 12, 232, 326 | ||||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||||
| EXSTYLE WS_EX_ACCEPTFILES | EXSTYLE WS_EX_ACCEPTFILES | ||||||
| CAPTION "Rufus 3.9.1622" | CAPTION "Rufus 3.9.1623" | ||||||
| FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | ||||||
| BEGIN | BEGIN | ||||||
|     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP |     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP | ||||||
|  | @ -395,8 +395,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 3,9,1622,0 |  FILEVERSION 3,9,1623,0 | ||||||
|  PRODUCTVERSION 3,9,1622,0 |  PRODUCTVERSION 3,9,1623,0 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -414,13 +414,13 @@ BEGIN | ||||||
|             VALUE "Comments", "https://rufus.ie" |             VALUE "Comments", "https://rufus.ie" | ||||||
|             VALUE "CompanyName", "Akeo Consulting" |             VALUE "CompanyName", "Akeo Consulting" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "3.9.1622" |             VALUE "FileVersion", "3.9.1623" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" | ||||||
|             VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" |             VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" | ||||||
|             VALUE "OriginalFilename", "rufus-3.9.exe" |             VALUE "OriginalFilename", "rufus-3.9.exe" | ||||||
|             VALUE "ProductName", "Rufus" |             VALUE "ProductName", "Rufus" | ||||||
|             VALUE "ProductVersion", "3.9.1622" |             VALUE "ProductVersion", "3.9.1623" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/ui.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/ui.c
									
										
									
									
									
								
							|  | @ -149,7 +149,7 @@ void GetMainButtonsWidth(HWND hDlg) | ||||||
| { | { | ||||||
| 	unsigned int i; | 	unsigned int i; | ||||||
| 	RECT rc; | 	RECT rc; | ||||||
| 	LONG style; | 	LONG_PTR style; | ||||||
| 	char download[64]; | 	char download[64]; | ||||||
| 
 | 
 | ||||||
| 	GetWindowRect(GetDlgItem(hDlg, main_button_ids[0]), &rc); | 	GetWindowRect(GetDlgItem(hDlg, main_button_ids[0]), &rc); | ||||||
|  | @ -167,9 +167,9 @@ void GetMainButtonsWidth(HWND hDlg) | ||||||
| 		static_strcpy(download, lmprintf(MSG_040)); | 		static_strcpy(download, lmprintf(MSG_040)); | ||||||
| 		CharUpperBuffU(download, sizeof(download)); | 		CharUpperBuffU(download, sizeof(download)); | ||||||
| 		bw = max(bw, GetTextSize(GetDlgItem(hDlg, IDC_SELECT), download).cx + (3 * cbw) / 2); | 		bw = max(bw, GetTextSize(GetDlgItem(hDlg, IDC_SELECT), download).cx + (3 * cbw) / 2); | ||||||
| 		style = GetWindowLong(GetDlgItem(hDlg, IDC_SELECT), GWL_STYLE); | 		style = GetWindowLongPtr(GetDlgItem(hDlg, IDC_SELECT), GWL_STYLE); | ||||||
| 		style|= BS_SPLITBUTTON; | 		style |= BS_SPLITBUTTON; | ||||||
| 		SetWindowLong(GetDlgItem(hDlg, IDC_SELECT), GWL_STYLE, style); | 		SetWindowLongPtr(GetDlgItem(hDlg, IDC_SELECT), GWL_STYLE, style); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -561,7 +561,7 @@ void SetSectionHeaders(HWND hDlg) | ||||||
| 		SendDlgItemMessageA(hDlg, section_control_ids[i], WM_SETFONT, (WPARAM)hf, TRUE); | 		SendDlgItemMessageA(hDlg, section_control_ids[i], WM_SETFONT, (WPARAM)hf, TRUE); | ||||||
| 		hCtrl = GetDlgItem(hDlg, section_control_ids[i]); | 		hCtrl = GetDlgItem(hDlg, section_control_ids[i]); | ||||||
| 		memset(wtmp, 0, sizeof(wtmp)); | 		memset(wtmp, 0, sizeof(wtmp)); | ||||||
| 		GetWindowTextW(hCtrl, wtmp, ARRAYSIZE(wtmp)); | 		GetWindowTextW(hCtrl, wtmp, ARRAYSIZE(wtmp) - 3); | ||||||
| 		wlen = wcslen(wtmp); | 		wlen = wcslen(wtmp); | ||||||
| 		wtmp[wlen++] = L' '; | 		wtmp[wlen++] = L' '; | ||||||
| 		wtmp[wlen++] = L' '; | 		wtmp[wlen++] = L' '; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue