[Scummvm-git-logs] scummvm master -> c07d109dba6801ed5fd42f00a265674b91007152

Strangerke noreply at scummvm.org
Wed Jun 18 21:49:49 UTC 2025


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

Summary:
1c335aec98 M4: Fix a couple of PVS Studio V1048 in adv_rails, some additional cleanup
c07d109dba M4: Fix several PVS Studio v547, v1020 and v1044 in conv and conv_io. Some cleanup


Commit: 1c335aec98e31a5e84ee0af92c2aff8df3c31be1
    https://github.com/scummvm/scummvm/commit/1c335aec98e31a5e84ee0af92c2aff8df3c31be1
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-06-18T22:48:19+01:00

Commit Message:
M4: Fix a couple of PVS Studio V1048 in adv_rails, some additional cleanup

Changed paths:
    engines/m4/adv_r/adv_rails.cpp


diff --git a/engines/m4/adv_r/adv_rails.cpp b/engines/m4/adv_r/adv_rails.cpp
index e936e8ef436..c5a1123d2cb 100644
--- a/engines/m4/adv_r/adv_rails.cpp
+++ b/engines/m4/adv_r/adv_rails.cpp
@@ -104,7 +104,7 @@ void ClearRails(void) {
 	}
 
 	if (_G(rails).myEdges) {
-		int32 edgeTableSize = (MAXRAILNODES * (MAXRAILNODES - 1)) >> 1;
+		const int32 edgeTableSize = (MAXRAILNODES * (MAXRAILNODES - 1)) >> 1;
 		for (i = 0; i < edgeTableSize; i++) {
 			_G(rails).myEdges[i] = 0;
 		}
@@ -141,7 +141,8 @@ noWalkRect *intr_add_no_walk_rect(int32 x1, int32 y1, int32 x2, int32 y2, int32
 	newRect->y2 = y2;
 
 	// Add the alternate walkto node - this node must exist
-	if ((newRect->alternateWalkToNode = AddRailNode(altX, altY, walkCodes, false)) < 0) {
+	newRect->alternateWalkToNode = AddRailNode(altX, altY, walkCodes, false);
+	if (newRect->alternateWalkToNode < 0) {
 		error_show(FL, 'IADN', "could not add node. coord: %d %d", altX, altY);
 	}
 
@@ -449,8 +450,7 @@ void CreateEdge(int32 node1, int32 node2, Buffer *walkCodes) {
 			error_term = xDiff >> 1;
 
 			// Loop along the x axis and adjust scanY as necessary
-			scanX = x1;
-			for (i = 0; ((i <= xDiff) && valid && (!finished)); i++) {
+			for (i = 0; ((i <= xDiff) && valid && !finished); i++) {
 
 				// Check if we have scanned off the edge of the buffer
 				if ((scanX >= width) || ((y_unit > 0) && (scanY >= height)) || ((y_unit < 0) && (scanY < 0))) {
@@ -503,8 +503,7 @@ void CreateEdge(int32 node1, int32 node2, Buffer *walkCodes) {
 			error_term = yDiff >> 1;
 
 			// Loop along the y axis and adjust scanX as necessary
-			scanY = y1;
-			for (i = 0; ((i <= yDiff) && valid && (!finished)); i++) {
+			for (i = 0; ((i <= yDiff) && valid && !finished); i++) {
 				// Check if we have scanned off the edge of the buffer
 				if (scanX >= width || ((y_unit > 0) && (scanY >= height)) || ((y_unit < 0) && (scanY < 0))) {
 					finished = true;
@@ -525,7 +524,7 @@ void CreateEdge(int32 node1, int32 node2, Buffer *walkCodes) {
 					// Update the error term
 					error_term += xDiff;
 
-					// If the error_term has exceeded the xdiff, we need to move one unit along the y axis
+					// If the error_term has exceeded the xDiff, we need to move one unit along the y axis
 					if (error_term >= yDiff) {
 						// Reset the error term
 						error_term -= yDiff;
@@ -666,11 +665,15 @@ bool RailNodeExists(int32 nodeID, int32 *nodeX, int32 *nodeY) {
 }
 
 int16 GetEdgeLength(int32 node1, int32 node2) {
-	if (!_G(rails).myEdges) return 0;
-	if (node1 == node2) return 0;
-	if (node2 < node1) {
+	if (!_G(rails).myEdges)
+		return 0;
+
+	if (node1 == node2)
+		return 0;
+
+	if (node2 < node1)
 		SWAP(node1, node2);
-	}
+
 	// If node1 is y and node2 is x, first find table entry ie. tableWidth * y + x, the subtract
 	// n(n+1)/2  since only the upper triangle of the table is stored...
 	const int32 index = (MAXRAILNODES - 1) * node1 + node2 - 1 - (node1 * (node1 + 1) >> 1);
@@ -847,8 +850,8 @@ bool GetShortestPath(int32 origID, int32 destID, railNode **shortPath) {
 
 		// Yes it is, therefore, we have a valid path, maybe the shortest...
 		if (edgeDist > 0) {
-			// Check whether the pathweight of the second last node + the edge to get to the last
-			// is less than the pathweight of the previously found shortest path
+			// Check whether the pathWeight of the second last node + the edge to get to the last
+			// is less than the pathWeight of the previously found shortest path
 			if (currNode->pathWeight + edgeDist < _G(rails).myNodes[destID]->pathWeight) {
 				// If so, store the new shortest path weight, and complete the path link
 				_G(rails).myNodes[destID]->pathWeight = (int16)(currNode->pathWeight + edgeDist);
@@ -915,7 +918,7 @@ bool GetShortestPath(int32 origID, int32 destID, railNode **shortPath) {
 						// For each different valid node, check to see if the currNode is adjacent to it
 						edgeDist = GetEdgeLength(currNode->nodeID, i);
 
-						// If it is a neighbor, and the pathweight reaching it through currNode is
+						// If it is a neighbor, and the pathWeight reaching it through currNode is
 						// less than the weight of any previous path that reached the same neighbor...
 						if ((edgeDist > 0) && ((currNode->pathWeight + edgeDist) < _G(rails).myNodes[i]->pathWeight)) {
 							// Now see if that neighbor is already part of the current shortest path
@@ -952,7 +955,7 @@ bool GetShortestPath(int32 origID, int32 destID, railNode **shortPath) {
 								}
 							} else {
 								// Else we don't know whether we can reach the destID from node i
-								// Set the pathweight of node i to the smaller value, and place it on the stack
+								// Set the pathWeight of node i to the smaller value, and place it on the stack
 								_G(rails).myNodes[i]->pathWeight = (int16)(currNode->pathWeight + edgeDist);
 								*_G(rails).stackTop++ = _G(rails).myNodes[i];
 							}


Commit: c07d109dba6801ed5fd42f00a265674b91007152
    https://github.com/scummvm/scummvm/commit/c07d109dba6801ed5fd42f00a265674b91007152
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-06-18T22:48:19+01:00

Commit Message:
M4: Fix several PVS Studio v547, v1020 and v1044 in conv and conv_io. Some cleanup

Changed paths:
    engines/m4/adv_r/conv.cpp
    engines/m4/adv_r/conv_io.cpp


diff --git a/engines/m4/adv_r/conv.cpp b/engines/m4/adv_r/conv.cpp
index 67c640927f8..620003df2ad 100644
--- a/engines/m4/adv_r/conv.cpp
+++ b/engines/m4/adv_r/conv.cpp
@@ -664,69 +664,55 @@ static int conv_next_node(Conv *c) {
 static int conv_process_entry(int entry_num, Conv *c, int mode) {
 	node_chunk *node;
 	lnode_chunk *lnode;
-	fall_chunk *fall;
 	int32 offset = 0, ent = 0, is_valid = 0, n = 0;
 	int32 next = 0, tag = 0, num_ents = 0;
 	int i = 0;
 	int	result = 1;
 
-	// Repeat fallthrough till done
-	for (;; ) {
-		// Start by getting the current NODE or LNODE
-		conv_ops_get_entry(ent, &next, &tag, c);
-		switch (tag) {
-		case LNODE_CHUNK:
-			lnode = get_lnode(c, ent);
-			ent += sizeof(lnode_chunk);
-			num_ents = lnode->num_entries;
-			entry_num = lnode->entry_num;
-			c->node_hash = lnode->hash;
-			break;
-
-		case NODE_CHUNK:
-			node = get_node(c, ent);
-			ent += sizeof(node_chunk);
-			num_ents = node->num_entries;
-			c->node_hash = node->hash;
-			break;
-
-		default:
-			break;
-		}
-
-		// ent will now be pointing at an ENTRY or FALLTHROUGH
-		const int32 sub_ent = next;
-		conv_ops_get_entry(sub_ent, &next, &tag, c);
-		switch (tag) {
-		case FALL_CHUNK:
-			// We either want to jump to a new node
-			// or skip to the first offset.
+	// Start by getting the current NODE or LNODE
+	conv_ops_get_entry(ent, &next, &tag, c);
+	switch (tag) {
+	case LNODE_CHUNK:
+		lnode = get_lnode(c, ent);
+		ent += sizeof(lnode_chunk);
+		num_ents = lnode->num_entries;
+		entry_num = lnode->entry_num;
+		c->node_hash = lnode->hash;
+		break;
 
-			fall = get_fall(c, sub_ent);
-			assert(fall);
+	case NODE_CHUNK:
+		node = get_node(c, ent);
+		ent += sizeof(node_chunk);
+		num_ents = node->num_entries;
+		c->node_hash = node->hash;
+		break;
 
-			// Do this to skip the fall chunk and all will be fine.
-			ent += sizeof(int32); //was get_long, sizeof( fall_chunk )
-			n++; //don't increment i.
-			break;
+	default:
+		break;
+	}
 
-		case ENTRY_CHUNK:
-			break;
+	// ent will now be pointing at an ENTRY or FALLTHROUGH
+	const int32 sub_ent = next;
+	conv_ops_get_entry(sub_ent, &next, &tag, c);
+	if (tag == FALL_CHUNK) {
+		// We either want to jump to a new node
+		// or skip to the first offset.
 
-		default:
-			break;
-		}
+		fall_chunk *fall = get_fall(c, sub_ent);
+		assert(fall);
 
-		if (result)
-			break;
+		// Do this to skip the fall chunk and all will be fine.
+		ent += sizeof(int32); //was get_long, sizeof( fall_chunk )
+		n++;                  //don't increment i.
 	}
 
+
 	// Not only i<entry_num, check to see entry->num_entries
 	while ((i < entry_num) && (n < num_ents)) {
 		offset = get_long(c, ent);
 		entry_chunk *entry = get_entry(c, ent + offset);
 
-		if (((entry->status) != 0) && ok_status(entry)) {
+		if ((entry->status != 0) && ok_status(entry)) {
 			i++;
 			is_valid = 1;
 		}
diff --git a/engines/m4/adv_r/conv_io.cpp b/engines/m4/adv_r/conv_io.cpp
index 89ee4fdd79a..c2af6d2880a 100644
--- a/engines/m4/adv_r/conv_io.cpp
+++ b/engines/m4/adv_r/conv_io.cpp
@@ -99,7 +99,7 @@ void conv_resume() {
 	conv_resume(conv_get_handle());
 }
 
-int conv_is_event_ready(void) {
+int conv_is_event_ready() {
 	return _GC(event_ready);
 }
 
@@ -108,7 +108,7 @@ void conv_set_event(int e) {
 	_GC(event_ready) = 1;
 }
 
-int conv_get_event(void) {
+int conv_get_event() {
 	_GC(event_ready) = 0;
 	return _GC(event);
 }
@@ -140,15 +140,15 @@ void conv_reset(const char *filename) {
 }
 
 
-void conv_reset_all(void) {
+void conv_reset_all() {
 	_G(conversations).conv_reset_all();
 }
 
-const char *conv_sound_to_play(void) {
+const char *conv_sound_to_play() {
 	return _G(cdd).mesg_snd_file;
 }
 
-int32 conv_whos_talking(void) {
+int32 conv_whos_talking() {
 	return _G(cdd).player_non_player;
 }
 
@@ -169,38 +169,30 @@ int conv_toggle_flags(entry_chunk *entry) {
 }
 
 int32 conv_get_decl_val(Conv *c, decl_chunk *decl) {
-	switch (decl->flags) {
-	case DECL_POINTER:
+	if (decl->flags == DECL_POINTER)
 		return *c->_pointers[decl->addrIndex];
 
-	default:
-		return decl->val;
-	}
+	return decl->val;
 }
 
 void conv_set_decl_val(Conv *c, decl_chunk *decl, int32 val) {
-	switch (decl->flags) {
-	case DECL_POINTER:
+	if (decl->flags == DECL_POINTER) {
 		decl->val = val;
 		*c->_pointers[decl->addrIndex] = val;
-		break;
-
-	default:
+	} else {
 		decl->val = val;
-		break;
 	}
 }
 
 void conv_export_value(Conv *c, int32 val, int index) {
-	int32 ent = 0, tag = 0, next;
-	int32 ent_old = 0;
+	int32 tag = 0, next;
 	int i = 0;
 
 	if (!c)
 		return;
 
-	ent_old = c->myCNode;
-	ent = 0;
+	const int32 ent_old = c->myCNode;
+	int32 ent = 0;
 	c->myCNode = 0;
 
 	while (ent < c->chunkSize) {
@@ -228,15 +220,14 @@ 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;
-	int32 ent_old = 0;
+	int32 tag = 0, next;
 	int	i = 0;
 
 	if (!c)
 		return;
 
-	ent_old = c->myCNode;
-	ent = 0;
+	const int32 ent_old = c->myCNode;
+	int32 ent = 0;
 	c->myCNode = 0;
 
 	while (ent < c->chunkSize) {
@@ -313,22 +304,16 @@ handled:
 
 void find_and_set_conv_name(Conv *c) {
 	int32 ent = 0, tag = 0, next = 0;
-	conv_chunk *conv;
 
 	c->myCNode = 0;
 
 	while (ent < c->chunkSize) {
 		conv_ops_get_entry(ent, &next, &tag, c);
 
-		switch (tag) {
-		case CONV_CHUNK:
-			conv = get_conv(c, ent);
+		if (tag == CONV_CHUNK) {
+			conv_chunk *conv = get_conv(c, ent);
 			assert(conv);
 			Common::strcpy_s(_GC(conv_name), get_string(c, c->myCNode + ent + sizeof(conv_chunk)));
-			break;
-
-		default:
-			break;
 		}
 		ent = next;
 	}
@@ -549,7 +534,7 @@ static Conv *conv_restore_state(Conv *c) {
 	int32 val;
 	int32 e_flags = 0;
 	int32 myCNode;
-	
+
 	char fname[13];
 	int file_size;
 
@@ -716,7 +701,7 @@ static void conv_set_disp_default(void) {
 }
 
 Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want_box) {
-	char fullpathname[MAX_FILENAME_SIZE];
+	char fullPathname[MAX_FILENAME_SIZE];
 
 	term_message("conv_load");
 
@@ -741,14 +726,14 @@ Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want
 	// if not in rooms.db, use actual filename
 	char *str = env_find(filename);
 	if (str)
-		Common::strcpy_s(fullpathname, str);
+		Common::strcpy_s(fullPathname, str);
 	else
-		Common::sprintf_s(fullpathname, "%s.chk", filename);
+		Common::sprintf_s(fullPathname, "%s.chk", filename);
 
-	SysFile fp(fullpathname);
+	SysFile fp(fullPathname);
 	if (!fp.exists()) {
 		// Force the file open
-		error_show(FL, 'CNVL', "couldn't conv_load %s", fullpathname);
+		error_show(FL, 'CNVL', "couldn't conv_load %s", fullPathname);
 	}
 
 	const int32 cSize = fp.size();




More information about the Scummvm-git-logs mailing list