Skip to content

Commit

Permalink
[RA] Fix issues pointed by address sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
giulianobelinassi authored and OmniBlade committed Dec 17, 2021
1 parent 4b74a59 commit acecf63
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions common/wspudp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ UDPInterfaceClass::UDPInterfaceClass(void)
UDPInterfaceClass::~UDPInterfaceClass(void)
{
while (BroadcastAddresses.Count()) {
delete BroadcastAddresses[0];
delete[] BroadcastAddresses[0];
BroadcastAddresses.Delete(0);
}

while (LocalAddresses.Count()) {
delete LocalAddresses[0];
delete[] LocalAddresses[0];
LocalAddresses.Delete(0);
}

Expand Down
2 changes: 1 addition & 1 deletion redalert/bdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3354,7 +3354,7 @@ short const* BuildingTypeClass::Occupy_List(bool placement) const
if (placement && Bib_And_Offset(bib, cell)) {

SmudgeTypeClass const& smudge = SmudgeTypeClass::As_Reference(bib);
static short _list[25];
static short _list[50];
short* dest = &_list[0];

/*
Expand Down
6 changes: 5 additions & 1 deletion redalert/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,12 @@ void DisplayClass::Set_Cursor_Shape(short const* list)
if (list) {
int w, h;
static short _list[50];
const short* src = list;
short* dst = _list;

while ((*dst++ = *src++) != REFRESH_EOL)
; /* Copy is done in condition. */

memcpy(_list, list, sizeof(_list));
CursorSize = _list;
Get_Occupy_Dimensions(w, h, CursorSize);
ZoneOffset = -(((h / 2) * MAP_CELL_W) + (w / 2));
Expand Down
7 changes: 6 additions & 1 deletion redalert/loaddlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,12 @@ int LoadOptionsClass::Process(void)
if (game_descr[0] == '(') {
char* ptr = strchr(game_descr, ')');
if (ptr != NULL) {
strcpy(game_descr, ptr + 1);
char* dst = game_descr;
const char* src = ptr + 1; // Skip ')'

// Don't use strcpy, as the memory regions overlap.
while ((*dst++ = *src++) != '\0')
; // Copy string
strtrim(game_descr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion redalert/sounddlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void SoundControlsClass::Process(void)
while (listbox.Count()) {
char const* ptr = listbox.Get_Item(0);
listbox.Remove_Item(ptr);
delete[](void*) ptr;
delete[] ptr;
}
}

Expand Down
17 changes: 17 additions & 0 deletions redalert/statbtn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,20 @@ void StaticButtonClass::Draw_Text(char const* text)
Fancy_Text_Print(text, x, Y, GadgetClass::Get_Color_Scheme(), TBLACK, PrintFlags);
}
}

/***********************************************************************************************
* StaticButtonClass::~StaticButtonClass -- Destructor of StaticButtonClass. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/09/2021 mrparrot : Created *
*=============================================================================================*/
StaticButtonClass::~StaticButtonClass(void)
{
delete[] String;
}
1 change: 1 addition & 0 deletions redalert/statbtn.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class StaticButtonClass : public GadgetClass
public:
StaticButtonClass(void);
StaticButtonClass(unsigned id, char const* text, TextPrintType style, int x, int y, int w = -1, int h = -1);
~StaticButtonClass(void);
virtual int Draw_Me(int forced = false);
virtual void Set_Text(char const* text, bool resize = false);

Expand Down
6 changes: 4 additions & 2 deletions redalert/techno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5341,7 +5341,8 @@ bool TechnoClass::Evaluate_Object(ThreatType method,
** Never recruit sticky guard units to defend a base.
*/
if (!infantry->Is_Weapon_Equipped()
|| (!MissionControl[infantry->Mission].IsRecruitable && Session.Type == GAME_NORMAL))
|| (!(infantry->Mission >= 0 && MissionControl[infantry->Mission].IsRecruitable)
&& Session.Type == GAME_NORMAL))
continue;
// (Mission != MISSION_GUARD_AREA || Session.Type == GAME_NORMAL)) continue;

Expand Down Expand Up @@ -5429,7 +5430,8 @@ bool TechnoClass::Evaluate_Object(ThreatType method,
** Never recruit sticky guard units to defend a base.
*/
if (!unit->Is_Weapon_Equipped()
|| (!MissionControl[unit->Mission].IsRecruitable && Session.Type == GAME_NORMAL))
|| (!(unit->Mission >= 0 && MissionControl[unit->Mission].IsRecruitable)
&& Session.Type == GAME_NORMAL))
continue;

/*
Expand Down

0 comments on commit acecf63

Please sign in to comment.