[Scummvm-git-logs] scummvm master -> 798a6164609fb539b9d7f863b744e41136dae4c0

Strangerke noreply at scummvm.org
Tue Jun 10 20:37:44 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
798a616460 M4: Fix some PVS Studio V668 issues, add some const in ws_hal


Commit: 798a6164609fb539b9d7f863b744e41136dae4c0
    https://github.com/scummvm/scummvm/commit/798a6164609fb539b9d7f863b744e41136dae4c0
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-06-10T21:37:33+01:00

Commit Message:
M4: Fix some PVS Studio V668 issues, add some const in ws_hal

Changed paths:
    engines/m4/adv_r/adv_file.cpp
    engines/m4/adv_r/conv_io.cpp
    engines/m4/core/rooms.cpp
    engines/m4/graphics/krn_pal.cpp
    engines/m4/gui/game_menu.cpp
    engines/m4/gui/gui_dialog.cpp
    engines/m4/gui/gui_menu_items.cpp
    engines/m4/wscript/ws_hal.cpp


diff --git a/engines/m4/adv_r/adv_file.cpp b/engines/m4/adv_r/adv_file.cpp
index 445f0586710..e4f835c3823 100644
--- a/engines/m4/adv_r/adv_file.cpp
+++ b/engines/m4/adv_r/adv_file.cpp
@@ -240,10 +240,6 @@ GrBuff *load_codes(SysFile *code_file) {
 	const int16 y_size = code_file->readSint16LE();
 
 	GrBuff *temp = new GrBuff(x_size, y_size);
-	if (!temp) {
-		error_show(FL, 'OOM!', "load_codes: %d bytes", (int16)(x_size * y_size));
-	}
-
 	Buffer *myBuff = temp->get_buffer();
 	byte *bufferHandle = myBuff->data;
 
@@ -352,9 +348,7 @@ static void recreate_animation_draw_screen(GrBuff **loadBuf) {
 		_G(game_buff_ptr) = nullptr;
 	}
 	_G(gameDrawBuff) = new GrBuff((**loadBuf).w, (**loadBuf).h);
-	if (!_G(gameDrawBuff)) error_show(FL, 'OOM!', "no memory for GrBuff");
-	gui_GrBuff_register(_G(kernel).letter_box_x, _G(kernel).letter_box_y, _G(gameDrawBuff),
-		SF_BACKGRND | SF_GET_ALL | SF_BLOCK_NONE, nullptr);
+	gui_GrBuff_register(_G(kernel).letter_box_x, _G(kernel).letter_box_y, _G(gameDrawBuff), SF_BACKGRND | SF_GET_ALL | SF_BLOCK_NONE, nullptr);
 	gui_buffer_activate((Buffer *)_G(gameDrawBuff));
 	vmng_screen_to_back((void *)_G(gameDrawBuff));
 	_G(game_buff_ptr) = vmng_screen_find(_G(gameDrawBuff), nullptr);
@@ -370,15 +364,16 @@ static void recreate_animation_draw_screen(GrBuff **loadBuf) {
 
 static void troll_for_colors(RGB8 *newPal, uint8 minPalEntry, uint8 maxPalEntry) {
 	bool gotOne = false;
-	for (int16 pal_iter = minPalEntry; pal_iter <= maxPalEntry; pal_iter++)	// accept any colors that came with the background
-		if (gotOne || (newPal[pal_iter].r | newPal[pal_iter].g | newPal[pal_iter].b))
-		{
+	for (int16 pal_iter = minPalEntry; pal_iter <= maxPalEntry; pal_iter++) { // accept any colors that came with the background
+		if (gotOne || (newPal[pal_iter].r | newPal[pal_iter].g | newPal[pal_iter].b)) {
 			gotOne = true;
 			// colors are 6 bit...
 			_G(master_palette)[pal_iter].r = newPal[pal_iter].r << 2;
 			_G(master_palette)[pal_iter].g = newPal[pal_iter].g << 2;
 			_G(master_palette)[pal_iter].b = newPal[pal_iter].b << 2;
 		}
+	}
+	
 	if (gotOne) {
 		gr_pal_interface(&_G(master_palette)[0]); // enforce interface colors
 	}
@@ -392,10 +387,9 @@ Common::String expand_name_2_RAW(const Common::String &name, int32 room_num) {
 			room_num = extract_room_num(name);
 
 		return Common::String::format("%d\\%s", room_num, tempName.c_str());
-
-	} else {
-		return tempName;
 	}
+
+	return tempName;
 }
 
 Common::String expand_name_2_HMP(const Common::String &name, int32 room_num) {
diff --git a/engines/m4/adv_r/conv_io.cpp b/engines/m4/adv_r/conv_io.cpp
index f275b219609..d7cb570a5a9 100644
--- a/engines/m4/adv_r/conv_io.cpp
+++ b/engines/m4/adv_r/conv_io.cpp
@@ -24,7 +24,6 @@
 #include "m4/adv_r/conv.h"
 #include "m4/adv_r/chunk_ops.h"
 #include "m4/adv_r/db_env.h"
-#include "m4/core/cstring.h"
 #include "m4/core/errors.h"
 #include "m4/vars.h"
 #include "m4/m4.h"
@@ -230,7 +229,6 @@ void conv_export_value_curr(int32 val, int index) {
 
 void conv_export_pointer(Conv *c, int32 *val, int index) {
 	int32 ent = 0, tag = 0, next;
-	decl_chunk *decl;
 	int32 ent_old = 0;
 	int	i = 0;
 
@@ -247,7 +245,7 @@ void conv_export_pointer(Conv *c, int32 *val, int index) {
 		switch (tag) {
 		case DECL_CHUNK:
 			if (i == index) {
-				decl = get_decl(c, ent);
+				decl_chunk *decl = get_decl(c, ent);
 
 				c->_pointers.push_back(val);
 				decl->addrIndex = c->_pointers.size() - 1;
@@ -271,8 +269,6 @@ void conv_export_pointer_curr(int32 *val, int index) {
 void conv_init(Conv *c) {
 	switch (c->exit_now) {
 	case CONV_OK:
-		break;
-
 	case CONV_QUIT:
 		break;
 
@@ -347,7 +343,7 @@ static void conv_save_state(Conv *c) {
 	int32 amt_to_write = 3 * sizeof(int32);	// Header size
 	int32 ent = 0;
 	int32 next, tag;	// receive conv_ops_get_entry results
-	int32 myCNode = c->myCNode;
+	const int32 myCNode = c->myCNode;
 	char fname[13];
 	memset(fname, 0, 13);
 
@@ -533,7 +529,7 @@ static void conv_save_state(Conv *c) {
 
 	} else {
 		// Append conversation
-		size_t oldSize = _GC(convSave).size();
+		const size_t oldSize = _GC(convSave).size();
 		file_size = amt_to_write + NAME_SIZE + sizeof(int32);
 
 		_GC(convSave).resize(_GC(convSave).size() + file_size);
@@ -546,15 +542,15 @@ static void conv_save_state(Conv *c) {
 
 static Conv *conv_restore_state(Conv *c) {
 	int32 ent = 0;
-	int32 tag, next, offset;
-
+	int32 tag, next;
+	int32 myCNode;
+	
 	entry_chunk *entry;
 	decl_chunk *decl;
 
 	short flag_index = 0;
 	int32 val;
 	int32 e_flags = 0;
-	int32 myCNode;
 
 	char fname[13];
 	int file_size = 0;
@@ -582,7 +578,7 @@ static Conv *conv_restore_state(Conv *c) {
 	// ------------------
 
 	Common::copy(&_GC(convSave)[0], &_GC(convSave)[0] + file_size, &conv_save_buff[0]);
-	offset = find_state(fname, conv_save_buff, file_size);
+	int32 offset = find_state(fname, conv_save_buff, file_size);
 
 	if (offset == -1)
 		goto i_am_so_done;
@@ -757,22 +753,13 @@ Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want
 		error_show(FL, 'CNVL', "couldn't conv_load %s", fullpathname);
 	}
 
-	int32 cSize = fp.size();
+	const int32 cSize = fp.size();
 
 	if (conv_get_handle() != nullptr) {
 		conv_unload();
 	}
 
 	Conv *convers = new Conv();
-
-	if (!convers) {
-		conv_set_handle(nullptr);
-		convers = nullptr;
-		fp.close();
-
-		return nullptr;
-	}
-
 	convers->chunkSize = cSize;
 	convers->conv = nullptr;
 	convers->myCNode = 0;
diff --git a/engines/m4/core/rooms.cpp b/engines/m4/core/rooms.cpp
index d71a21f5681..f7878bfb844 100644
--- a/engines/m4/core/rooms.cpp
+++ b/engines/m4/core/rooms.cpp
@@ -255,8 +255,6 @@ void Sections::get_ipl() {
 	}
 
 	_G(inverse_pal) = new InvPal(filename.c_str());
-	if (!_G(inverse_pal))
-		error_show(FL, 'OOM!', "loading ipl: %s", filename.c_str());
 }
 
 void Sections::get_walker() {
@@ -367,7 +365,7 @@ void Sections::parse_player_command_now() {
 
 void Sections::pal_game_task() {
 	int32 status;
-	int delta = 0;
+	int delta;
 	Common::String line;
 
 	if (!player_commands_allowed())
@@ -377,7 +375,7 @@ void Sections::pal_game_task() {
 
 	if (!_G(kernel).pause) {
 		if (_G(toggle_cursor) != CURSCHANGE_NONE) {
-			CursorChange change = _G(toggle_cursor);
+			const CursorChange change = _G(toggle_cursor);
 			_G(toggle_cursor) = CURSCHANGE_NONE;
 			g_vars->getHotkeys()->toggle_through_cursors(change);
 		}
diff --git a/engines/m4/graphics/krn_pal.cpp b/engines/m4/graphics/krn_pal.cpp
index 037824e63e7..3ebbdb1c472 100644
--- a/engines/m4/graphics/krn_pal.cpp
+++ b/engines/m4/graphics/krn_pal.cpp
@@ -226,7 +226,7 @@ void krn_fade_from_grey(RGB8 *pal, int32 steps, int32 delay, int32 fadeType) {
 	// Get the screen
 	Buffer *grey_screen = _G(gameDrawBuff)->get_buffer();
 
-	// load original faded greys into the free indexes (no pixels have these indexs yet)
+	// load original faded greys into the free indexes (no pixels have these indexes yet)
 	gr_pal_set_range(_GP(fadeToMe), FREE_START, NUM_FREE);   // Load fadeToMe colors into VGA
 
 	make_translation_table(_GP(trick)); // This is used in fade_to_grey too!
diff --git a/engines/m4/gui/game_menu.cpp b/engines/m4/gui/game_menu.cpp
index b869b688220..1a29c797187 100644
--- a/engines/m4/gui/game_menu.cpp
+++ b/engines/m4/gui/game_menu.cpp
@@ -173,10 +173,6 @@ Sprite *SaveLoadMenuBase::menu_CreateThumbnail(int32 *spriteSize) {
 	}
 
 	GrBuff *thumbNail = new GrBuff((MAX_VIDEO_X + 1) / 3, (MAX_VIDEO_Y + 1) / 3);
-	if (!thumbNail) {
-		return nullptr;
-	}
-
 	Buffer *destBuff = thumbNail->get_buffer();
 	if (!destBuff) {
 		return nullptr;
diff --git a/engines/m4/gui/gui_dialog.cpp b/engines/m4/gui/gui_dialog.cpp
index ee820e74b17..eff58ada22b 100644
--- a/engines/m4/gui/gui_dialog.cpp
+++ b/engines/m4/gui/gui_dialog.cpp
@@ -152,11 +152,6 @@ Dialog *DialogCreateAbsolute(int32 x1, int32 y1, int32 x2, int32 y2, uint32 scrn
 	dialog->h = y2 - y1 + 1;
 
 	dialog->dlgBuffer = new GrBuff(x2 - x1 + 1, y2 - y1 + 1);
-
-	if (!dialog->dlgBuffer) {
-		return nullptr;
-	}
-
 	dialog->num_items = 0;
 	dialog->itemList = nullptr;
 
@@ -1324,10 +1319,6 @@ TextScrn *TextScrn_Create(int32 x1, int32 y1, int32 x2, int32 y2, int32 luminanc
 
 	myTextScrn->textScrnBuffer = new GrBuff(myTextScrn->w, myTextScrn->h);
 
-	if (!myTextScrn->textScrnBuffer) {
-		return nullptr;
-	}
-
 	if (!vmng_screen_create(x1, y1, x2, y2, SCRN_TEXT, scrnFlags | SF_TRANSPARENT, (void *)myTextScrn, (RefreshFunc)TextScrn_Show, TextScrn_EventHandler)) {
 		return nullptr;
 	}
diff --git a/engines/m4/gui/gui_menu_items.cpp b/engines/m4/gui/gui_menu_items.cpp
index eb52628778b..98a4a851b1f 100644
--- a/engines/m4/gui/gui_menu_items.cpp
+++ b/engines/m4/gui/gui_menu_items.cpp
@@ -219,9 +219,6 @@ GrBuff *guiMenu::copyBackground(guiMenu *myMenu, int32 x, int32 y, int32 w, int3
 
 	// Create a new grbuff struct
 	GrBuff *copyOfBackground = new GrBuff(w, h);
-	if (!copyOfBackground) {
-		return nullptr;
-	}
 
 	// Get the source and destination buffers
 	Buffer *srcBuff = myMenu->menuBuffer->get_buffer();
diff --git a/engines/m4/wscript/ws_hal.cpp b/engines/m4/wscript/ws_hal.cpp
index 3c7ada16271..22023df5ae4 100644
--- a/engines/m4/wscript/ws_hal.cpp
+++ b/engines/m4/wscript/ws_hal.cpp
@@ -123,7 +123,7 @@ void ws_LogErrorMsg(const char *filename, uint32 line, const char *fmt, ...) {
 	va_list	argPtr;
 	va_start(argPtr, fmt);
 
-	Common::String msg = Common::String::vformat(fmt, argPtr);
+	const Common::String msg = Common::String::vformat(fmt, argPtr);
 	va_end(argPtr);
 
 	error("%s", msg.c_str());
@@ -201,10 +201,10 @@ void ws_DoDisplay(Buffer *background, int16 *depth_table, Buffer *screenCodeBuff
 
 	Buffer *halScrnBuf = _G(gameDrawBuff)->get_buffer();
 
-	int32 scrnX1 = myScreen->x1;
-	int32 scrnY1 = myScreen->y1;
+	const int32 scrnX1 = myScreen->x1;
+	const int32 scrnY1 = myScreen->y1;
 
-	bool greyMode = krn_GetGreyMode();
+	const bool greyMode = krn_GetGreyMode();
 
 	// Initialize the drawRectList to the deadRectList
 	drawRectList = _GWS(deadRectList);
@@ -437,19 +437,19 @@ void ws_hal_RefreshWoodscriptBuffer(cruncher *myCruncher, Buffer *background,
 }
 
 void GetBezCoeffs(frac16 *ctrlPoints, frac16 *coeffs) {
-	frac16 x0 = ctrlPoints[0];
-	frac16 x0mult3 = (x0 << 1) + x0;
-	frac16 x1mult3 = (ctrlPoints[2] << 1) + ctrlPoints[2];
-	frac16 x1mult6 = x1mult3 << 1;
-	frac16 x2mult3 = (ctrlPoints[4] << 1) + ctrlPoints[4];
-	frac16 x3 = ctrlPoints[6];
-
-	frac16 y0 = ctrlPoints[1];
-	frac16 y0mult3 = (y0 << 1) + y0;
-	frac16 y1mult3 = (ctrlPoints[3] << 1) + ctrlPoints[3];
-	frac16 y1mult6 = y1mult3 << 1;
-	frac16 y2mult3 = (ctrlPoints[5] << 1) + ctrlPoints[5];
-	frac16 y3 = ctrlPoints[7];
+	const frac16 x0 = ctrlPoints[0];
+	const frac16 x0mult3 = (x0 << 1) + x0;
+	const frac16 x1mult3 = (ctrlPoints[2] << 1) + ctrlPoints[2];
+	const frac16 x1mult6 = x1mult3 << 1;
+	const frac16 x2mult3 = (ctrlPoints[4] << 1) + ctrlPoints[4];
+	const frac16 x3 = ctrlPoints[6];
+
+	const frac16 y0 = ctrlPoints[1];
+	const frac16 y0mult3 = (y0 << 1) + y0;
+	const frac16 y1mult3 = (ctrlPoints[3] << 1) + ctrlPoints[3];
+	const frac16 y1mult6 = y1mult3 << 1;
+	const frac16 y2mult3 = (ctrlPoints[5] << 1) + ctrlPoints[5];
+	const frac16 y3 = ctrlPoints[7];
 
 	coeffs[0] = -(int)x0 + x1mult3 - x2mult3 + x3;
 	coeffs[2] = x0mult3 - x1mult6 + x2mult3;
@@ -611,7 +611,7 @@ void Cel_msr(Anim8 *myAnim8) {
 		error_show(FL, 'WSAI');
 	}
 
-	int32 scaler = FixedMul(myRegs[IDX_S], 100 << 16) >> 16;
+	const int32 scaler = FixedMul(myRegs[IDX_S], 100 << 16) >> 16;
 
 	myCCB->scaleX = myRegs[IDX_W] < 0 ? -scaler : scaler;
 	myCCB->scaleY = scaler;




More information about the Scummvm-git-logs mailing list