Skip to content

Commit

Permalink
fix: sonar bugs and gha checks (#2633)
Browse files Browse the repository at this point in the history
Fix to use std::cmp_greater and iteration using total ++

Co-authored-by: Elson Costa <elsongabriel@hotmail.com>
  • Loading branch information
dudantas and elsongabriel committed May 15, 2024
1 parent c9d1035 commit 84c9658
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build-ubuntu-dummy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
os: [ubuntu-22.04]
buildtype: [linux-release, linux-debug]
include:
- os: ubuntu-20.04
triplet: x64-linux
- os: ubuntu-22.04
triplet: x64-linux

Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
os: [ubuntu-22.04]
buildtype: [linux-release, linux-debug]
include:
- os: ubuntu-20.04
triplet: x64-linux
- os: ubuntu-22.04
triplet: x64-linux

Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool PlayerTitle::checkMount(uint32_t amount) {
uint8_t total = 0;
for (const auto &mount : g_game().mounts.getMounts()) {
if (m_player.hasMount(mount)) {
total = total++;
total++;
}
}
return total >= amount;
Expand Down
21 changes: 11 additions & 10 deletions src/creatures/players/cyclopedia/player_title.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,28 @@ struct Title {
Title() = default;

Title(uint8_t id, CyclopediaTitle_t type, std::string maleName, std::string description, uint32_t amount, bool permanent) :
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_description(std::move(description)), m_amount(amount),
m_permanent(permanent) { }
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(), m_description(std::move(description)),
m_amount(amount), m_permanent(permanent), m_skill(0), m_race(0) { }

Title(uint8_t id, CyclopediaTitle_t type, std::string maleName, std::string description, uint32_t amount, bool permanent, std::string femaleName) :
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_description(std::move(description)), m_amount(amount),
m_permanent(permanent), m_femaleName(std::move(femaleName)) { }
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)), m_description(std::move(description)),
m_amount(amount), m_permanent(permanent), m_skill(0), m_race(0) { }

Title(uint8_t id, CyclopediaTitle_t type, std::string maleName, std::string femaleName, std::string description, uint8_t skill) :
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)), m_description(std::move(description)),
m_skill(skill) { }
m_amount(0), m_permanent(false), m_skill(skill), m_race(0) { }

Title(uint8_t id, CyclopediaTitle_t type, uint16_t race, std::string maleName, std::string femaleName, std::string description) :
m_id(id), m_type(type), m_race(race), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)),
m_description(std::move(description)) { }
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)), m_description(std::move(description)),
m_amount(0), m_permanent(false), m_skill(0), m_race(race) { }

Title(uint8_t id, CyclopediaTitle_t type, uint16_t race, std::string maleName, std::string femaleName, std::string description, uint32_t amount, bool permanent) :
m_id(id), m_type(type), m_race(race), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)),
m_description(std::move(description)), m_amount(amount), m_permanent(permanent) { }
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)), m_description(std::move(description)),
m_amount(amount), m_permanent(permanent), m_skill(0), m_race(race) { }

Title(uint8_t id, CyclopediaTitle_t type, std::string maleName, std::string description, bool permanent) :
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_description(std::move(description)), m_permanent(permanent) { }
m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(), m_description(std::move(description)),
m_amount(0), m_permanent(permanent), m_skill(0), m_race(0) { }

bool operator==(const Title &other) const {
return m_id == other.m_id;
Expand Down
1 change: 0 additions & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8266,7 +8266,6 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect) {
}

void Game::playerFriendSystemAction(std::shared_ptr<Player> player, uint8_t type, uint8_t titleId) {
uint32_t playerGUID = player->getGUID();
if (type == 0x0E) {
player->title()->setCurrentTitle(titleId);
player->sendCyclopediaCharacterBaseInformation();
Expand Down
2 changes: 1 addition & 1 deletion src/items/items.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class Items {

static const std::string getAugmentNameByType(Augment_t augmentType);

static const bool isAugmentWithoutValueDescription(Augment_t augmentType) {
static bool isAugmentWithoutValueDescription(Augment_t augmentType) {
static std::vector<Augment_t> vector = {
Augment_t::IncreasedDamage,
Augment_t::PowerfulImpact,
Expand Down
13 changes: 6 additions & 7 deletions src/utils/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,16 +1560,15 @@ void capitalizeWords(std::string &source) {

void capitalizeWordsIgnoringString(std::string &source, const std::string stringToIgnore) {
toLowerCaseString(source);
uint8_t size = (uint8_t)source.size();
uint8_t indexFound = source.find(stringToIgnore);
auto size = static_cast<uint8_t>(source.size());
auto indexFound = source.find(stringToIgnore);

for (uint8_t i = 0; i < size; i++) {
if (indexFound != std::string::npos && (i > indexFound - 1) && i < (indexFound + stringToIgnore.size())) {
if (indexFound != std::string::npos && indexFound > 0 && std::cmp_greater(i, static_cast<uint8_t>(indexFound - 1)) && i < (indexFound + stringToIgnore.size())) {
continue;
}
if (i == 0) {
source[i] = (char)toupper(source[i]);
} else if (source[i - 1] == ' ' || source[i - 1] == '\'') {
source[i] = (char)toupper(source[i]);
if (i == 0 || source[i - 1] == ' ' || source[i - 1] == '\'') {
source[i] = static_cast<char>(std::toupper(source[i]));
}
}
}
Expand Down

0 comments on commit 84c9658

Please sign in to comment.