8000 0.8.0 -> 0.9.0 Patch Example by winrid · Pull Request #271 · netpanzer/netpanzer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

0.8.0 -> 0.9.0 Patch Example #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 512 commits into
base: 0.8.7
Choose a base branch
from
Open

0.8.0 -> 0.9.0 Patch Example #271

wants to merge 512 commits into from

Conversation

winrid
Copy link
Member
@winrid winrid commented Feb 10, 2025

No description provided.

andy5995 and others added 30 commits January 15, 2024 23:28
* Fixes Not Compiling on Windows

* cleanup

* fixing silent (?) crash

* Remove <filesystem>
Needed for #95
[skip ci]
Related to #43

Code courtesy of ChatGPT and lightly modified by me.
ChatGPT failed. Trying phind now.
The amd64 image gets overwritten after the arm64 image is pushed. I
think this will work? Maybe
docker/build-push-action#733 ?
Right now when it's enabled, NP crashes before it gets to the main menu.
I think we should disable it until the game can actually be played.
* if CIRRUS and darwin, then change the test a little

* CI: Add skip rules to Cirrus CI

closes #132
We shouldn't link to GitHub when the file is in the current directory structure. The links will still be rendered properly on GH. Helps with editor integration.
@winrid winrid changed the title 0.80 -> 0.9.0 Patch Example 0.8.0 -> 0.9.0 Patch Example Feb 10, 2025
github-advanced-security[bot]
github-advanced-security bot found potential problems Feb 10, 2025
< 6DB6 div class="ml-md-2 mt-md-0 mt-2 flex-shrink-0"> View reviewed changes
const std::vector<UnitBase *> &uc =
UnitInterface::getPlayerUnits(PlayerInterface::getLocalPlayerIndex());

for (Uint8 id_list_index = 0; id_list_index < uc.size(); ++id_list_index) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
id_list_index
of type Uint8 and
call to size
of wider type size_type.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the variable id_list_index is of a type that is at least as wide as the type returned by uc.size(). The best way to achieve this is to change the type of id_list_index from Uint8 to size_t, which matches the type of uc.size().

  • Change the type of id_list_index from Uint8 to size_t.
  • This change should be made in the file src/NetPanzer/Bot/Bot.cpp on line 132.
Suggested changeset 1
src/NetPanzer/Bot/Bot.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Bot/Bot.cpp b/src/NetPanzer/Bot/Bot.cpp
--- a/src/NetPanzer/Bot/Bot.cpp
+++ b/src/NetPanzer/Bot/Bot.cpp
@@ -131,3 +131,3 @@
 
-  for (Uint8 id_list_index = 0; id_list_index < uc.size(); ++id_list_index) {
+  for (size_t id_list_index = 0; id_list_index < uc.size(); ++id_list_index) {
     unit_ptr = uc[id_list_index];
EOF
@@ -131,3 +131,3 @@

for (Uint8 id_list_index = 0; id_list_index < uc.size(); ++id_list_index) {
for (size_t id_list_index = 0; id_list_index < uc.size(); ++id_list_index) {
unit_ptr = uc[id_list_index];
Copilot is powered by AI and may make mistakes. Always verify output.
if (uc.size() > 0) {
UnitBase *unitsl = uc[rand() % uc.size()];

for (Uint8 i = 0; i < uc.size(); ++i) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
i
of type Uint8 and
call to size
of wider type size_type.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the variable i is of a type that can safely be compared with the return value of uc.size(). The best way to do this is to change the type of i from Uint8 to size_t, which is the type returned by the size() function of the vector. This ensures that the comparison is made between two values of the same type, preventing any potential overflow or unexpected behavior.

Suggested changeset 1
src/NetPanzer/Bot/BotPlayer.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Bot/BotPlayer.cpp b/src/NetPanzer/Bot/BotPlayer.cpp
--- a/src/NetPanzer/Bot/BotPlayer.cpp
+++ b/src/NetPanzer/Bot/BotPlayer.cpp
@@ -115,3 +115,3 @@
 
-        for (Uint8 i = 0; i < uc.size(); ++i) {
+        for (size_t i = 0; i < uc.size(); ++i) {
           UnitBase *unit = uc[i];
EOF
@@ -115,3 +115,3 @@

for (Uint8 i = 0; i < uc.size(); ++i) {
for (size_t i = 0; i < uc.size(); ++i) {
UnitBase *unit = uc[i];
Copilot is powered by AI and may make mistakes. Always verify output.
UnitInterface::getPlayerUnits(playerIndex);
unsigned char threat_count = 0;

for (Uint8 i = 0; i < uc.size(); ++i) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
i
of type Uint8 and
call to size
of wider type size_type.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the variable i used in the loop condition has a type that is at least as wide as the type returned by the size() method of the vector. The best way to achieve this is to change the type of i from Uint8 to std::vector<UnitBase *>::size_type, which is the type returned by the size() method of the vector. This ensures that the comparison is made between values of the same type, preventing any potential overflow or unexpected behavior.

Suggested changeset 1
src/NetPanzer/Bot/BotPlayer.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Bot/BotPlayer.cpp b/src/NetPanzer/Bot/BotPlayer.cpp
--- a/src/NetPanzer/Bot/BotPlayer.cpp
+++ b/src/NetPanzer/Bot/BotPlayer.cpp
@@ -315,3 +315,3 @@
 
-      for (Uint8 i = 0; i < uc.size(); ++i) {
+      for (std::vector<UnitBase *>::size_type i = 0; i < uc.size(); ++i) {
         UnitBase *enemyUnit;
EOF
@@ -315,3 +315,3 @@

for (Uint8 i = 0; i < uc.size(); ++i) {
for (std::vector<UnitBase *>::size_type i = 0; i < uc.size(); ++i) {
UnitBase *enemyUnit;
Copilot is powered by AI and may make mistakes. Always verify output.
UnitInterface::getPlayerUnits(playerIndex);
unsigned char moving_count = 0;

for (Uint8 i = 0; i < uct.size(); ++i) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
i
of type Uint8 and
call to size
of wider type size_type.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the variable i used in the loop condition has a type that is at least as wide as the type returned by the size() method of the vector. The best way to achieve this is to change the type of i from Uint8 to std::vector<UnitBase *>::size_type, which is the type returned by the size() method.

This change ensures that the comparison in the loop condition is between two values of the same type, preventing any potential overflow or unexpected behavior.

Suggested changeset 1
src/NetPanzer/Bot/BotPlayer.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Bot/BotPlayer.cpp b/src/NetPanzer/Bot/BotPlayer.cpp
--- a/src/NetPanzer/Bot/BotPlayer.cpp
+++ b/src/NetPanzer/Bot/BotPlayer.cpp
@@ -315,3 +315,3 @@
 
-      for (Uint8 i = 0; i < uc.size(); ++i) {
+      for (std::vector<UnitBase *>::size_type i = 0; i < uc.size(); ++i) {
         UnitBase *enemyUnit;
@@ -381,3 +381,3 @@
 
-        for (Uint8 i = 0; i < uct.size(); ++i) {
+        for (std::vector<UnitBase *>::size_type i = 0; i < uct.size(); ++i) {
           if (uct[i]->unit_state.moving == true) {
EOF
@@ -315,3 +315,3 @@

for (Uint8 i = 0; i < uc.size(); ++i) {
for (std::vector<UnitBase *>::size_type i = 0; i < uc.size(); ++i) {
UnitBase *enemyUnit;
@@ -381,3 +381,3 @@

for (Uint8 i = 0; i < uct.size(); ++i) {
for (std::vector<UnitBase *>::size_type i = 0; i < uct.size(); ++i) {
if (uct[i]->unit_state.moving == true) {
Copilot is powered by AI and may make mistakes. Always verify output.
dbHeader->tile_count = file.readULE16();
file.read(&dbHeader->palette, sizeof(dbHeader->palette), 1);
void TileSet::computeTileConsts(void) {
tile_size = tile_set_info.x_pix * tile_set_info.y_pix;

Check failure

Code scanning / CodeQL

Multiplication result converted to larger type High

Multiplication result may overflow 'int' before it is converted to 'unsigned long'.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the multiplication is performed using the larger type (unsigned long) to avoid overflow. This can be achieved by casting one of the operands to unsigned long before performing the multiplication. This way, the multiplication will be done in the larger type, and the result will be correctly assigned to tile_size.

Suggested changeset 1
src/NetPanzer/Classes/TileSet.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Classes/TileSet.cpp b/src/NetPanzer/Classes/TileSet.cpp
--- a/src/NetPanzer/Classes/TileSet.cpp
+++ b/src/NetPanzer/Classes/TileSet.cpp
@@ -52,3 +52,3 @@
 void TileSet::computeTileConsts(void) {
-  tile_size = tile_set_info.x_pix * tile_set_info.y_pix;
+  tile_size = static_cast<unsigned long>(tile_set_info.x_pix) * tile_set_info.y_pix;
 }
EOF
@@ -52,3 +52,3 @@
void TileSet::computeTileConsts(void) {
tile_size = tile_set_info.x_pix * tile_set_info.y_pix;
tile_size = static_cast<unsigned long>(tile_set_info.x_pix) * tile_set_info.y_pix;
}
Copilot is powered by AI and may make mistakes. Always verify output.

size_t map_size = map_info.width * map_info.height;
size_t map_size = map_info.width * map_info.height;

Check failure

Code scanning / CodeQL

Multiplication result converted to larger type High

Multiplication result may overflow 'int' before it is converted to 'size_t'.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the multiplication is performed using the larger type (size_t) to avoid overflow. This can be achieved by casting one or both operands to size_t before performing the multiplication. This way, the multiplication will be done using the larger type, and the result will be correctly stored in the size_t variable.

Suggested changeset 1
src/NetPanzer/Classes/WorldMap.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Classes/WorldMap.cpp b/src/NetPanzer/Classes/WorldMap.cpp
--- a/src/NetPanzer/Classes/WorldMap.cpp
+++ b/src/NetPanzer/Classes/WorldMap.cpp
@@ -53,3 +53,3 @@
 
-    size_t map_size = map_info.width * map_info.height;
+    size_t map_size = static_cast<size_t>(map_info.width) * static_cast<size_t>(map_info.height);
 
EOF
@@ -53,3 +53,3 @@

size_t map_size = map_info.width * map_info.height;
size_t map_size = static_cast<size_t>(map_info.width) * static_cast<size_t>(map_info.height);

Copilot is powered by AI and may make mistakes. Always verify output.
}

void ObjectiveInterface::disownPlayerObjectives(PlayerID player_id) {
for (Uint16 i = 0; i < num_objectives; ++i) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
i
of type Uint16 and
num_objectives
of wider type int.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the variable i is of a type that is at least as wide as the type of num_objectives. Since num_objectives is of type int, we should change the type of i to int as well. This will prevent any potential overflow issues and ensure that the comparison behaves as expected.

Suggested changeset 1
src/NetPanzer/Objectives/ObjectiveInterface.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Objectives/ObjectiveInterface.cpp b/src/NetPanzer/Objectives/ObjectiveInterface.cpp
--- a/src/NetPanzer/Objectives/ObjectiveInterface.cpp
+++ b/src/NetPanzer/Objectives/ObjectiveInterface.cpp
@@ -423,3 +423,3 @@
 void ObjectiveInterface::disownPlayerObjectives(PlayerID player_id) {
-  for (Uint16 i = 0; i < num_objectives; ++i) {
+  for (int i = 0; i < num_objectives; ++i) {
     if (objective_list[i]->occupying_player &&
@@ -448,3 +448,3 @@
 Objective* ObjectiveInterface::getObjectiveAtWorldXY(const iXY& loc) {
-  for (Uint16 i = 0; i < num_objectives; ++i) {
+  for (int i = 0; i < num_objectives; ++i) {
     if (objective_list[i]->selection_box.contains(loc)) {
EOF
@@ -423,3 +423,3 @@
void ObjectiveInterface::disownPlayerObjectives(PlayerID player_id) {
for (Uint16 i = 0; i < num_objectives; ++i) {
for (int i = 0; i < num_objectives; ++i) {
if (objective_list[i]->occupying_player &&
@@ -448,3 +448,3 @@
Objective* ObjectiveInterface::getObjectiveAtWorldXY(const iXY& loc) {
for (Uint16 i = 0; i < num_objectives; ++i) {
for (int i = 0; i < num_objectives; ++i) {
if (objective_list[i]->selection_box.contains(loc)) {
Copilot is powered by AI and may make mistakes. Always verify output.
}

Objective* ObjectiveInterface::getObjectiveAtWorldXY(const iXY& loc) {
for (Uint16 i = 0; i < num_objectives; ++i) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
i
of type Uint16 and
num_objectives
of wider type int.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the type of the loop variable i is at least as wide as the type of num_objectives. The best way to achieve this is to change the type of i from Uint16 to int, which matches the type of num_objectives. This change will prevent any potential overflow issues and ensure that the comparison behaves as expected.

Suggested changeset 1
src/NetPanzer/Objectives/ObjectiveInterface.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Objectives/ObjectiveInterface.cpp b/src/NetPanzer/Objectives/ObjectiveInterface.cpp
--- a/src/NetPanzer/Objectives/ObjectiveInterface.cpp
+++ b/src/NetPanzer/Objectives/ObjectiveInterface.cpp
@@ -42
10000
3,3 +423,3 @@
 void ObjectiveInterface::disownPlayerObjectives(PlayerID player_id) {
-  for (Uint16 i = 0; i < num_objectives; ++i) {
+  for (int i = 0; i < num_objectives; ++i) {
     if (objective_list[i]->occupying_player &&
@@ -448,3 +448,3 @@
 Objective* ObjectiveInterface::getObjectiveAtWorldXY(const iXY& loc) {
-  for (Uint16 i = 0; i < num_objectives; ++i) {
+  for (int i = 0; i < num_objectives; ++i) {
     if (objective_list[i]->selection_box.contains(loc)) {
EOF
@@ -423,3 +423,3 @@
void ObjectiveInterface::disownPlayerObjectives(PlayerID player_id) {
for (Uint16 i = 0; i < num_objectives; ++i) {
for (int i = 0; i < num_objectives; ++i) {
if (objective_list[i]->occupying_player &&
@@ -448,3 +448,3 @@
Objective* ObjectiveInterface::getObjectiveAtWorldXY(const iXY& loc) {
for (Uint16 i = 0; i < num_objectives; ++i) {
for (int i = 0; i < num_objectives; ++i) {
if (objective_list[i]->selection_box.contains(loc)) {
Copilot is powered by AI and may make mistakes. Always verify output.
// Create the correct number of unit information slots.
unitParticleInfo.resize(UnitProfileInterface::getNumUnitTypes());

for (unsigned short i = 0; i < UnitProfileInterface::getNumUnitTypes(); i++) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
i
of type unsigned short and
call to getNumUnitTypes
of wider type unsigned int.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the variable i is of a type that is at least as wide as the return type of UnitProfileInterface::getNumUnitTypes(). The best way to fix this without changing existing functionality is to change the type of i from unsigned short to unsigned int.

Suggested changeset 1
src/NetPanzer/Particles/ParticleInterface.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Particles/ParticleInterface.cpp b/src/NetPanzer/Particles/ParticleInterface.cpp
--- a/src/NetPanzer/Particles/ParticleInterface.cpp
+++ b/src/NetPanzer/Particles/ParticleInterface.cpp
@@ -1011,3 +1011,3 @@
 
-  for (unsigned short i = 0; i < UnitProfileInterface::getNumUnitTypes(); i++) {
+  for (unsigned int i = 0; i < UnitProfileInterface::getNumUnitTypes(); i++) {
     unsigned short vector_index = i * GameManager::ststylesnum;
EOF
@@ -1011,3 +1011,3 @@

for (unsigned short i = 0; i < UnitProfileInterface::getNumUnitTypes(); i++) {
for (unsigned int i = 0; i < UnitProfileInterface::getNumUnitTypes(); i++) {
unsigned short vector_index = i * GameManager::ststylesnum;
Copilot is powered by AI and may make mistakes. Always verify output.

if (NetworkState::status == _network_state_server) // server only
{
for (unsigned char i = 0; i < GameConfig::getUnitStylesNum(); i++) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
i
of type unsigned char and
call to getUnitStylesNum
of wider type unsigned short.

Copilot Autofix

AI 4 months ago

To fix the problem, we need to ensure that the variable i is of a type that is at least as wide as the type returned by GameConfig::getUnitStylesNum(). Since GameConfig::getUnitStylesNum() returns an unsigned short, we should change the type of i to unsigned short to match.

Suggested changeset 1
src/NetPanzer/Views/Game/UStyleSelectionView.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/NetPanzer/Views/Game/UStyleSelectionView.cpp b/src/NetPanzer/Views/Game/UStyleSelectionView.cpp
--- a/src/NetPanzer/Views/Game/UStyleSelectionView.cpp
+++ b/src/NetPanzer/Views/Game/UStyleSelectionView.cpp
@@ -97,3 +97,3 @@
   {
-    for (unsigned char i = 0; i < GameConfig::getUnitStylesNum(); i++) {
+    for (unsigned short i = 0; i < GameConfig::getUnitStylesNum(); i++) {
       NPString sstyle = GameConfig::getUnitStyle(i);
@@ -108,3 +108,3 @@
   } else {
-    for (unsigned char i = 0; i < GameManager::ststylesnum; i++) {
+    for (unsigned short i = 0; i < GameManager::ststylesnum; i++) {
       NPString sstyle = GameManager::stlist[i];
EOF
@@ -97,3 +97,3 @@
{
for (unsigned char i = 0; i < GameConfig::getUnitStylesNum(); i++) {
for (unsigned short i = 0; i < GameConfig::getUnitStylesNum(); i++) {
NPString sstyle = GameConfig::getUnitStyle(i);
@@ -108,3 +108,3 @@
} else {
for (unsigned char i = 0; i < GameManager::ststylesnum; i++) {
for (unsigned short i = 0; i < GameManager::ststylesnum; i++) {
NPString sstyle = GameManager::stlist[i];
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0