[Scummvm-git-logs] scummvm master -> c0eaeae4064d7a1858c3e4330b5d7efd804be0b0
Strangerke
noreply at scummvm.org
Tue Jun 24 04:27:26 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:
c0eaeae406 M4: Fix a large number of PVS V634 issues, some cleanup and const in m4\core
Commit: c0eaeae4064d7a1858c3e4330b5d7efd804be0b0
https://github.com/scummvm/scummvm/commit/c0eaeae4064d7a1858c3e4330b5d7efd804be0b0
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-06-24T05:27:07+01:00
Commit Message:
M4: Fix a large number of PVS V634 issues, some cleanup and const in m4\core
Changed paths:
engines/m4/core/cstring.cpp
engines/m4/core/errors.cpp
engines/m4/core/errors.h
engines/m4/core/imath.cpp
engines/m4/core/imath.h
engines/m4/core/param.cpp
engines/m4/core/param.h
diff --git a/engines/m4/core/cstring.cpp b/engines/m4/core/cstring.cpp
index 96053a5d583..e52586f4765 100644
--- a/engines/m4/core/cstring.cpp
+++ b/engines/m4/core/cstring.cpp
@@ -75,7 +75,7 @@ void cstrncpy(char *dest, const char *src, const int16 max_len) {
char *cstrupr(char *src) {
if (!src)
- return 0;
+ return nullptr;
char *mark = src;
do {
@@ -88,7 +88,7 @@ char *cstrupr(char *src) {
char *cstr_lower(char *src) {
if (!src)
- return 0;
+ return nullptr;
char *mark = src;
do {
@@ -104,10 +104,9 @@ int xtoi(char *string) {
return 0;
int value = 0;
- int item;
while (*string) {
- item = *string++;
+ int item = *string++;
if (cstr_isdigit(item))
value = (value << 4) + item - '0';
else
@@ -127,10 +126,7 @@ int strpos(char *key, char *target) {
if (!key || !target)
return 0;
- char *tmp;
-
- tmp = strstr(target, key);
-
+ char *tmp = strstr(target, key);
if (tmp)
return(tmp - target + 1);
@@ -170,14 +166,12 @@ void strseg(char *work, char *work2, int indx, int count) {
*/
void strins(char *work, char *newStr, int indx) {
if (!work || !newStr) {
- newStr = 0;
+ newStr = nullptr;
return;
}
- int l, l1;
-
- l1 = (strlen(work) - indx + 2);
- l = strlen(newStr);
+ const int l1 = (strlen(work) - indx + 2);
+ const int l = strlen(newStr);
memmove(work + indx + l - 1, work + indx - 1, l1);
memcpy(work + indx - 1, newStr, l);
}
@@ -187,11 +181,10 @@ void str_purge_trailing_spaces(char *myline) {
if (!myline)
return;
- char *search;
int again = true;
do {
- search = &myline[strlen(myline) - 1];
+ char *search = &myline[strlen(myline) - 1];
if ((*search == 0x20) || (*search == 0x09))
*search = 0;
else
@@ -207,14 +200,13 @@ void str_purge_all_spaces(char *text) {
if (!text)
return;
- char work[256];
- char *mark;
-
str_purge_trailing_spaces(text);
- mark = text;
- while (*mark && ((*mark == ' ') || (*mark == 0x09))) mark++;
+ char *mark = text;
+ while (*mark && ((*mark == ' ') || (*mark == 0x09)))
+ mark++;
+ char work[256];
Common::strcpy_s(work, 256, mark);
Common::strcpy_s(text, 256, work);
}
@@ -222,11 +214,9 @@ void str_purge_all_spaces(char *text) {
char *str_strip_final_lf(char *mystring) {
if (!mystring)
- return 0;
+ return nullptr;
- char *temp;
-
- temp = strrchr(mystring, 0x0a);
+ char *temp = strrchr(mystring, 0x0a);
if (temp != nullptr) {
*temp = '\0';
}
@@ -237,9 +227,7 @@ void str_add_final_lf(char *mystring) {
if (!mystring)
return;
- char *temp;
-
- temp = mystring + strlen(mystring);
+ char *temp = mystring + strlen(mystring);
*(temp++) = 0x0a;
*temp = '\0';
}
@@ -287,10 +275,8 @@ int dtoi(char *string) {
return 0;
int value = 0;
- int item;
-
while (*string) {
- item = *string++;
+ const char item = *string++;
if (cstr_isdigit(item))
value = (value * 10) + item - '0';
else
diff --git a/engines/m4/core/errors.cpp b/engines/m4/core/errors.cpp
index 45a2f6a4777..98858558a06 100644
--- a/engines/m4/core/errors.cpp
+++ b/engines/m4/core/errors.cpp
@@ -29,7 +29,7 @@ inline static bool quadchar_equals_string(uint32 code, const Common::String &str
return READ_BE_UINT32(str.c_str()) == code;
}
-void error_show(const char *filename, uint32 line, quadchar errorcode, const char *fmt, ...) {
+void error_show(const char *filename, uint32 line, quadchar errorCode, const char *fmt, ...) {
assert(fmt);
va_list va;
@@ -40,11 +40,11 @@ void error_show(const char *filename, uint32 line, quadchar errorcode, const cha
error("%s", msg.c_str());
}
-void error_show(const char *filename, uint32 line, quadchar errorcode) {
- error_show(filename, line, errorcode, "No extra description");
+void error_show(const char *filename, uint32 line, quadchar errorCode) {
+ error_show(filename, line, errorCode, "No extra description");
}
-void error_look_up(quadchar errorcode, char *result_string) {
+void error_look_up(quadchar errorCode, char *result_string) {
Common::File f;
*result_string = '\0';
@@ -57,7 +57,7 @@ void error_look_up(quadchar errorcode, char *result_string) {
buffer = f.readString();
const char *mark = buffer.c_str() + 1;
- if (quadchar_equals_string(errorcode, buffer) || quadchar_equals_string(errorcode, mark)) {
+ if (quadchar_equals_string(errorCode, buffer) || quadchar_equals_string(errorCode, mark)) {
const char *src = (const char *)buffer.c_str() + 5;
int16 count = 0;
diff --git a/engines/m4/core/errors.h b/engines/m4/core/errors.h
index 0647dffe12d..f9b283f4891 100644
--- a/engines/m4/core/errors.h
+++ b/engines/m4/core/errors.h
@@ -30,9 +30,9 @@ namespace M4 {
#define FL __FILE__,__LINE__
#define ERROR_FILE "error.m4"
-void NORETURN_PRE error_show(const char *filename, uint32 line, quadchar errorcode, const char *fmt, ...) NORETURN_POST;
-void NORETURN_PRE error_show(const char *filename, uint32 line, quadchar errorcode) NORETURN_POST;
-void error_look_up(quadchar errorcode, char *result_string);
+void NORETURN_PRE error_show(const char *filename, uint32 line, quadchar errorCode, const char *fmt, ...) NORETURN_POST;
+void NORETURN_PRE error_show(const char *filename, uint32 line, quadchar errorCode) NORETURN_POST;
+void error_look_up(quadchar errorCode, char *result_string);
} // namespace M4
diff --git a/engines/m4/core/imath.cpp b/engines/m4/core/imath.cpp
index a8d10ba8f72..82d1f372a78 100644
--- a/engines/m4/core/imath.cpp
+++ b/engines/m4/core/imath.cpp
@@ -27,8 +27,8 @@ namespace M4 {
unsigned long sqrtul(unsigned long v) {
unsigned long r = 0, s;
-#define STEP(k) s = r + (1L << k * 2); r >>= 1; \
- if (s <= v) { v -= s; r |= (1L << k * 2); }
+#define STEP(k) s = r + (1L << (k * 2)); r >>= 1; \
+ if (s <= v) { v -= s; r |= (1L << (k * 2)); }
STEP(15);
STEP(14);
@@ -65,8 +65,8 @@ int32 imath_abs(int32 a) {
static int32 seed;
-void imath_seed(int32 seednum) {
- seed = seednum;
+void imath_seed(int32 seedNum) {
+ seed = seedNum;
}
uint32 imath_random() {
@@ -74,14 +74,12 @@ uint32 imath_random() {
}
int32 imath_ranged_rand(int32 a, int32 b) {
- int32 result;
- result = (a + (((1 + imath_abs(b - a)) * imath_random()) >> 16));
+ const int32 result = (a + (((1 + imath_abs(b - a)) * imath_random()) >> 16));
return result;
}
frac16 imath_ranged_rand16(frac16 a, frac16 b) {
- frac16 result;
- result = ((a + MulSF16(1 + imath_abs(b - a), imath_random())));
+ const frac16 result = ((a + MulSF16(1 + imath_abs(b - a), imath_random())));
return result;
}
@@ -90,17 +88,19 @@ bool imath_rand_bool(int max) {
}
frac16 dist2d(int32 x1, int32 y1, int32 x2, int32 y2) {
- if ((x2 -= x1) < 0) x2 = -x2;
- if ((y2 -= y1) < 0) y2 = -y2;
+ if ((x2 -= x1) < 0)
+ x2 = -x2;
+ if ((y2 -= y1) < 0)
+ y2 = -y2;
return (x2 + y2 - (((x2 > y2) ? y2 : x2) >> 1));
}
-#define STEP(k) s = r + (1L << k * 2); r >>= 1; \
- if (s <= v) { v -= s; r |= (1L << k * 2); }
+#define STEP(k) s = r + (1L << (k * 2)); r >>= 1; \
+ if (s <= v) { v -= s; r |= (1L << (k * 2)); }
frac16 SqrtF16(frac16 n) {
- ulong r = 0, s, v;
- v = (ulong)n;
+ ulong r = 0, s;
+ ulong v = (ulong)n;
STEP(15);
STEP(14);
@@ -124,13 +124,10 @@ frac16 SqrtF16(frac16 n) {
#define DIV_128_PI 0x28be61
frac16 ArcTan(frac16 x, frac16 y) {
- double floatX, floatY, result;
- frac16 fracResult;
-
- floatX = (float)(x >> 16) + (float)((float)(x & 0xffff) / (float)65536);
- floatY = (float)(y >> 16) + (float)((float)(y & 0xffff) / (float)65536);
- result = atan2(floatY, floatX);
- fracResult = (((int32)(floor(result))) << 16) + (int32)(floor((result - floor(result)) * 65536));
+ const double floatX = (float)(x >> 16) + (float)((float)(x & 0xffff) / (float)65536);
+ const double floatY = (float)(y >> 16) + (float)((float)(y & 0xffff) / (float)65536);
+ const double result = atan2(floatY, floatX);
+ frac16 fracResult = (((int32)(floor(result))) << 16) + (int32)(floor((result - floor(result)) * 65536));
fracResult = MulSF16(fracResult, DIV_128_PI);
if (fracResult < 0) fracResult += 0x1000000;
return fracResult;
@@ -153,21 +150,21 @@ uint16 convert_intel16(uint16 a) {
}
frac16 FixedMul(frac16 a, frac16 b) {
- float ta = a;
- float tb = b;
+ const float ta = a;
+ const float tb = b;
return (frac16)((ta * tb) / 65536.0);
}
frac16 FixedDiv(frac16 a, frac16 b) {
- float ta = a;
- float tb = b;
+ const float ta = a;
+ const float tb = b;
return (frac16)((ta / tb) * 65536.0);
}
frac16 FixedMulDiv(frac16 a, frac16 b, frac16 c) {
- float ta = a;
- float tb = b;
- float tc = c;
+ const float ta = a;
+ const float tb = b;
+ const float tc = c;
return (frac16)((ta * tb) / tc);
}
diff --git a/engines/m4/core/imath.h b/engines/m4/core/imath.h
index 376c0dd521b..0650dcea0f6 100644
--- a/engines/m4/core/imath.h
+++ b/engines/m4/core/imath.h
@@ -49,7 +49,7 @@ int32 imath_max(int32 a, int32 b);
int32 imath_min(int32 a, int32 b);
int32 imath_abs(int32 a);
-void imath_seed(int32 seednum);
+void imath_seed(int32 seedNum);
uint32 imath_random();
int32 imath_ranged_rand(int32 a, int32 b);
frac16 imath_ranged_rand16(frac16 a, frac16 b);
diff --git a/engines/m4/core/param.cpp b/engines/m4/core/param.cpp
index fc82e3b2f1f..c497ecec92f 100644
--- a/engines/m4/core/param.cpp
+++ b/engines/m4/core/param.cpp
@@ -67,7 +67,7 @@ void parse_all_flags() {
}
if (ConfMan.hasKey("T")) {
- int room = ConfMan.getInt("T");
+ const int room = ConfMan.getInt("T");
if (room) {
_G(kernel).teleported_in = true;
diff --git a/engines/m4/core/param.h b/engines/m4/core/param.h
index 26430c89d69..1e7919ba96a 100644
--- a/engines/m4/core/param.h
+++ b/engines/m4/core/param.h
@@ -22,8 +22,6 @@
#ifndef M4_INFO_H
#define M4_INFO_H
-#include "common/file.h"
-
namespace M4 {
/**
More information about the Scummvm-git-logs
mailing list