Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/missiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,7 @@ bool GuardianTryFireAt(Missile &missile, Point target)
return false;

const Player &player = Players[missile._misource];
int dmg = GenerateRnd(10) + (player.getCharacterLevel() / 2) + 1;
dmg = ScaleSpellEffect(dmg, missile._mispllvl);
int dmg = ScaleSpellEffect(dmg, missile._mispllvl);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one is probably not affecting the binary, since the compiler optimizing non read data

That's not correct. dmg was being used before your change, as it gets passed into ScaleSpellEffect(). Your compiler should be giving you a warning here.

[ 55%] Building CXX object Source/CMakeFiles/libdevilutionx.dir/missiles.cpp.o
.../DevilutionX/Source/missiles.cpp: In function ‘bool devilution::{anonymous}::GuardianTryFireAt(devilution::Missile&, devilution::Point)’:
.../DevilutionX/Source/missiles.cpp:729:23: warning: unused variable ‘player’ [-Wunused-variable]
  729 |         const Player &player = Players[missile._misource];
      |                       ^~~~~~
.../DevilutionX/Source/missiles.cpp:730:35: warning: ‘dmg’ may be used uninitialized [-Wmaybe-uninitialized]
  730 |         int dmg = ScaleSpellEffect(dmg, missile._mispllvl);
      |                   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
.../DevilutionX/Source/missiles.cpp:730:13: note: ‘dmg’ was declared here
  730 |         int dmg = ScaleSpellEffect(dmg, missile._mispllvl);
      |             ^~~


const Direction dir = GetDirection(position, target);
AddMissile(position, target, dir, MissileID::Firebolt, TARGET_MONSTERS, missile._misource, missile._midam, missile.sourcePlayer()->GetSpellLevel(SpellID::Guardian), &missile);
Expand Down Expand Up @@ -1707,11 +1706,12 @@ void AddSearch(Missile &missile, AddMissileParameter & /*parameter*/)
lvl = player.getCharacterLevel() * 2;
missile.duration = lvl + 10 * missile._mispllvl + 245;

// Casting again increase spell duration
for (auto &other : Missiles) {
if (&other != &missile && missile.isSameSource(other) && other._mitype == MissileID::Search) {
const int r1 = missile.duration;
const int r2 = other.duration;
if (r2 < INT_MAX - r1)
if (r2 <= INT_MAX - r1)
other.duration = r1 + r2;
missile._miDelFlag = true;
break;
Expand Down