Skip to content

Commit

Permalink
Clean up compiler warnings for all platforms (#138)
Browse files Browse the repository at this point in the history
We have a number of compiler warnings in the current code.   Let's
get rid of them all.

Add -Werror to prevent new compile warnings from creeping in
  • Loading branch information
jt-traub authored Oct 6, 2023
1 parent b5cef9b commit 0854b69
Show file tree
Hide file tree
Showing 23 changed files with 184 additions and 182 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GAME ?= standard

CPLUS = g++
CC = gcc
CFLAGS = -g -I. -I.. -Wall -std=c++11
CFLAGS = -g -I. -I.. -Wall -Werror -std=c++11

RULESET_OBJECTS = extra.o map.o monsters.o rules.o world.o

Expand Down
63 changes: 32 additions & 31 deletions aregion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ void ARegion::WriteReport(Areport *f, Faction *fac, int month,
if (type == R_NEXUS) {
int len = strlen(AC_STRING)+2*strlen(Globals->WORLD_NAME);
char *nexus_desc = new char[len];
sprintf(nexus_desc, AC_STRING, Globals->WORLD_NAME,
snprintf(nexus_desc, len, AC_STRING, Globals->WORLD_NAME,
Globals->WORLD_NAME);
f->PutStr("");
f->PutStr(nexus_desc);
Expand Down Expand Up @@ -2913,8 +2913,8 @@ void makeRivers(Map* map, ARegionArray* arr, std::vector<WaterBody*>& waterBodie

size_t sz = waterBodies.size();
int distances[sz][sz];
for (int i = 0; i < sz; i++) {
for (int j = 0; j < sz; j++) {
for (size_t i = 0; i < sz; i++) {
for (size_t j = 0; j < sz; j++) {
distances[i][j] = INT32_MAX;
}
}
Expand Down Expand Up @@ -2975,13 +2975,13 @@ void makeRivers(Map* map, ARegionArray* arr, std::vector<WaterBody*>& waterBodie
});

int riverName = 0;
for (int i = 0; i < sz; i++) {
for (size_t i = 0; i < sz; i++) {
std::cout << "Connecting water body " << i << std::endl;

std::vector<std::pair<int, int>> candidates;
WaterBody* source = waterBodies[i];

for (int j = 0; j < sz; j++) {
for (size_t j = 0; j < sz; j++) {
if (i == j) {
continue;
}
Expand All @@ -3007,7 +3007,9 @@ void makeRivers(Map* map, ARegionArray* arr, std::vector<WaterBody*>& waterBodie
continue;
}

graph.setInclusion([ source, target, &rivers, &waterBodies ](ARegion* current, ARegion* next) {
// Commented out waterBodies to match that it's not used currently due to that if statement
// in the lambda being commented out.
graph.setInclusion([ source, target, &rivers/*, &waterBodies*/ ](ARegion* current, ARegion* next) {
if (source->includes(next)) {
// river can't go through source water body
return false;
Expand Down Expand Up @@ -3254,7 +3256,7 @@ std::vector<graphs::Location2D> getPoints(const int w, const int h,

graphs::Location2D loc;
do {
loc = { x: getrandom(w), y: getrandom(h) };
loc = { .x = getrandom(w), .y = getrandom(h) };
}
while (!onIsIncluded(loc));

Expand Down Expand Up @@ -3345,7 +3347,6 @@ std::vector<graphs::Location2D> getPointsFromList(

while (!processing.empty()) {
int i = getrandom(processing.size());
auto next = processing.at(i);
processing.erase(processing.begin() + i);

int count = 0;
Expand Down Expand Up @@ -3699,13 +3700,13 @@ void economy(ARegionArray* arr, const int w, const int h) {
std::string name = getEthnicName(makeRoll(1, w * h), etnos);

reg->ManualSetup({
terrain: terrain,
habitat: terrain->pop + 1,
prodWeight: 1,
addLair: false,
addSettlement: true,
settlementName: name,
settlementSize: size
.terrain = terrain,
.habitat = terrain->pop + 1,
.prodWeight = 1,
.addLair = false,
.addSettlement = true,
.settlementName = name,
.settlementSize = size
});

visited.insert(reg);
Expand Down Expand Up @@ -3735,13 +3736,13 @@ void economy(ARegionArray* arr, const int w, const int h) {
bool addLair = getrandom(100) < terrain->lairChance;

reg->ManualSetup({
terrain: terrain,
habitat: terrain->pop + 1,
prodWeight: 1,
addLair: addLair,
addSettlement: false,
settlementName: std::string(),
settlementSize: 0
.terrain = terrain,
.habitat = terrain->pop + 1,
.prodWeight = 1,
.addLair = addLair,
.addSettlement = false,
.settlementName = std::string(),
.settlementSize = 0
});
}
}
Expand Down Expand Up @@ -3865,8 +3866,8 @@ void ARegionList::AddHistoricalBuildings(ARegionArray* arr, const int w, const i

size_t sz = cities.size();
int distances[sz][sz];
for (int i = 0; i < sz; i++) {
for (int j = i + 1; j < sz; j++) {
for (size_t i = 0; i < sz; i++) {
for (size_t j = i + 1; j < sz; j++) {
if (i == j) {
distances[i][j] = 0;
continue;
Expand All @@ -3875,8 +3876,8 @@ void ARegionList::AddHistoricalBuildings(ARegionArray* arr, const int w, const i
auto start = cities[i];
auto end = cities[j];

graphs::Location2D startLoc = { x: start->xloc, y: start->yloc };
graphs::Location2D endLoc = { x: end->xloc, y: end->yloc };
graphs::Location2D startLoc = { .x = start->xloc, .y = start->yloc };
graphs::Location2D endLoc = { .x = end->xloc, .y = end->yloc };

std::unordered_map<graphs::Location2D, graphs::Location2D> cameFrom;
std::unordered_map<graphs::Location2D, double> costSoFar;
Expand All @@ -3900,14 +3901,14 @@ void ARegionList::AddHistoricalBuildings(ARegionArray* arr, const int w, const i
}

std::unordered_set<ARegion*> connected;
for (int i = 0; i < sz; i++) {
for (size_t i = 0; i < sz; i++) {
auto start = cities[i];

if (connected.find(start) != connected.end()) {
continue;
}

for (int j = 0; j < sz; j++) {
for (size_t j = 0; j < sz; j++) {
auto dist = distances[i][j];
if (!dist || dist > 8) {
continue;
Expand All @@ -3923,8 +3924,8 @@ void ARegionList::AddHistoricalBuildings(ARegionArray* arr, const int w, const i

std::string name = "Road to " + std::string(end->town->name->Str());

graphs::Location2D startLoc = { x: start->xloc, y: start->yloc };
graphs::Location2D endLoc = { x: end->xloc, y: end->yloc };
graphs::Location2D startLoc = { .x = start->xloc, .y = start->yloc };
graphs::Location2D endLoc = { .x = end->xloc, .y = end->yloc };

std::unordered_map<graphs::Location2D, graphs::Location2D> cameFrom;
std::unordered_map<graphs::Location2D, double> costSoFar;
Expand Down Expand Up @@ -4191,4 +4192,4 @@ const std::unordered_map<ARegion*, graphs::Node<ARegion*>> breadthFirstSearch(AR
}

return cameFrom;
}
}
14 changes: 7 additions & 7 deletions astring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AString::AString(const char *s)
AString::AString(int l)
{
char buf[16];
sprintf(buf,"%d",l);
snprintf(buf, 16, "%d", l);
len = strlen(buf);
str = new char[len+1];
strcpy(str,buf);
Expand All @@ -64,7 +64,7 @@ AString::AString(int l)
AString::AString(unsigned int l)
{
char buf[16];
sprintf(buf,"%u",l);
snprintf(buf, 16, "%u", l);
len = strlen(buf);
str = new char[len+1];
strcpy(str,buf);
Expand Down Expand Up @@ -118,22 +118,22 @@ AString & AString::operator=(const char *c)
return *this;
}

int AString::operator==(char *s)
int AString::operator==(char *s) const
{
return isEqual(s);
}

int AString::operator==(const char *s)
int AString::operator==(const char *s) const
{
return isEqual(s);
}

int AString::operator==(const AString &s)
int AString::operator==(const AString &s) const
{
return isEqual(s.str);
}

int AString::isEqual(const char *temp2)
int AString::isEqual(const char *temp2) const
{
char *temp1 = str;

Expand Down Expand Up @@ -306,7 +306,7 @@ AString *AString::getlegal()
}

if (!j) {
delete temp;
delete[] temp;
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions astring.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class AString : public AListElem {
AString(const std::string &);
~AString();

int operator==(const AString &);
int operator==(char *);
int operator==(const char *);
int operator==(const AString &) const;
int operator==(char *) const;
int operator==(const char *) const;
int CheckPrefix(const AString &);
AString operator+(const AString &);
AString & operator+=(const AString &);
Expand All @@ -72,7 +72,7 @@ class AString : public AListElem {

int len;
char *str;
int isEqual(const char *);
int isEqual(const char *) const;
};

const std::string plural(int count, const std::string &one, const std::string &many);
Expand Down
2 changes: 1 addition & 1 deletion basic/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,5 +1230,5 @@ void ARegionList::FinalSetupGates()
r->gatemonth = getrandom(12);;
}
}
delete used;
delete[] used;
}
2 changes: 1 addition & 1 deletion edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ void Game::EditGameRegionTerrain( ARegion *pReg )
pReg->gate = getrandom(ngates);
while (used[pReg->gate])
pReg->gate = getrandom(ngates);
delete used;
delete[] used;
pReg->gate++;
} else {
int gatenum = getrandom(regions.numberofgates) + 1;
Expand Down
6 changes: 3 additions & 3 deletions events-assassination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ void AssassinationFact::GetEvents(std::list<Event> &events) {
}

events.push_back({
category: EventCategory::EVENT_ASSASSINATION,
score: 1,
text: buffer.str()
.category = EventCategory::EVENT_ASSASSINATION,
.score = 1,
.text = buffer.str()
});
}
24 changes: 12 additions & 12 deletions events-battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ const Event cityCapture(BattleFact* fact) {
}

return {
category: EventCategory::EVENT_CITY_CAPTURE,
score: fact->location.settlementType + 2,
text: buffer.str()
.category = EventCategory::EVENT_CITY_CAPTURE,
.score = fact->location.settlementType + 2,
.text = buffer.str()
};
}

Expand Down Expand Up @@ -277,9 +277,9 @@ const Event monsterHunt(BattleFact* fact) {
}

return {
category: EventCategory::EVENT_MONSTER_HUNT,
score: 1,
text: buffer.str()
.category = EventCategory::EVENT_MONSTER_HUNT,
.score = 1,
.text = buffer.str()
};
}

Expand Down Expand Up @@ -322,9 +322,9 @@ const Event monsterAggresion(BattleFact* fact) {
}

return {
category: EventCategory::EVENT_MONSTER_AGGRESSION,
score: 1,
text: buffer.str()
.category = EventCategory::EVENT_MONSTER_AGGRESSION,
.score = 1,
.text = buffer.str()
};
}

Expand Down Expand Up @@ -569,9 +569,9 @@ const Event pvpBattle(BattleFact* fact) {
if (totalFMI > 0) score += 1;

return {
category: EventCategory::EVENT_BATTLE,
score: score,
text: buffer.str()
.category = EventCategory::EVENT_BATTLE,
.score = score,
.text = buffer.str()
};
}

Expand Down
30 changes: 15 additions & 15 deletions events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ void populateSettlementLandmark(std::vector<Landmark> &landmarks, ARegion *reg,
std::string title = townType(reg->town->TownType()) + " of " + name;

landmarks.push_back({
type: events::LandmarkType::SETTLEMENT,
name: name,
title: title,
distance: distance,
weight: 10
.type = events::LandmarkType::SETTLEMENT,
.name = name,
.title = title,
.distance = distance,
.weight = 10
});
}

Expand Down Expand Up @@ -164,11 +164,11 @@ void populateRegionLandmark(std::vector<Landmark> &landmarks, ARegion *source, A
}

landmarks.push_back({
type: type,
name: name,
title: title,
distance: distance,
weight: weight
.type = type,
.name = name,
.title = title,
.distance = distance,
.weight = weight
});
}

Expand Down Expand Up @@ -204,11 +204,11 @@ void populateForitifcationLandmark(std::vector<Landmark> &landmarks, ARegion *re
std::string title = std::string(ObjectDefs[building->type].name) + " " + name;

landmarks.push_back({
type: events::LandmarkType::FORTIFICATION,
name: name,
title: title,
distance: distance,
weight: 5
.type = events::LandmarkType::FORTIFICATION,
.name = name,
.title = title,
.distance = distance,
.weight = 5
});
}

Expand Down
2 changes: 1 addition & 1 deletion fracas/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,5 +1200,5 @@ void ARegionList::FinalSetupGates()
r->gatemonth = getrandom(12);;
}
}
delete used;
delete[] used;
}
Loading

0 comments on commit 0854b69

Please sign in to comment.