diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 6671d93e6..380e04ef4 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -678,7 +678,7 @@ void CPlayerInterface::battleStacksHealedRes(const std::vectorgeneraltexth->allTexts[361 + textOff].c_str(), attacker->getCreature()->nameSing.c_str(), + snprintf(textBuf, 1000, CGI->generaltexth->allTexts[361 + textOff].c_str(), attacker->getCreature()->nameSing.c_str(), healedStacks[0].second, defender->getCreature()->namePl.c_str()); battleInt->console->addText(textBuf); } diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index 6a75eefbb..0a2cb05ed 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -832,7 +832,7 @@ void CBattleInterface::bFleef() heroName = defendingHeroInstance->name; //calculating text char buffer[1000]; - sprintf(buffer, CGI->generaltexth->allTexts[340].c_str(), heroName.c_str()); //The Shackles of War are present. %s can not retreat! + snprintf(buffer, 1000, CGI->generaltexth->allTexts[340].c_str(), heroName.c_str()); //The Shackles of War are present. %s can not retreat! //printing message curInt->showInfoDialog(std::string(buffer), comps); @@ -1523,7 +1523,7 @@ void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse) BonusList defenseBonuses = *(stack->getBonuses(Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE))); defenseBonuses.remove_if(Selector::durationType(Bonus::STACK_GETS_TURN)); //remove bonuses gained from defensive stance int val = stack->Defense() - defenseBonuses.totalValue(); - sprintf(txt, CGI->generaltexth->allTexts[txtid].c_str(), (stack->count != 1) ? stack->getCreature()->namePl.c_str() : stack->getCreature()->nameSing.c_str(), val); + sprintf(txt, 4000, CGI->generaltexth->allTexts[txtid].c_str(), (stack->count != 1) ? stack->getCreature()->namePl.c_str() : stack->getCreature()->nameSing.c_str(), val); console->addText(txt); } } @@ -1797,19 +1797,19 @@ void CBattleInterface::printConsoleAttacked( const CStack * defender, int dmg, i int end = 0; if (attacker) //ignore if stacks were killed by spell { - end = sprintf(tabh, CGI->generaltexth->allTexts[attacker->count > 1 ? 377 : 376].c_str(), + end = snprintf(tabh, 200, CGI->generaltexth->allTexts[attacker->count > 1 ? 377 : 376].c_str(), (attacker->count > 1 ? attacker->getCreature()->namePl.c_str() : attacker->getCreature()->nameSing.c_str()), dmg); } if(killed > 0) { if(killed > 1) { - sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, + snprintf(tabh + end, 400, CGI->generaltexth->allTexts[379].c_str(), killed, multiple ? CGI->generaltexth->allTexts[43].c_str() : defender->getCreature()->namePl.c_str()); // creatures perish } else //killed == 1 { - sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), + snprintf(tabh + end, 400, CGI->generaltexth->allTexts[378].c_str(), multiple ? CGI->generaltexth->allTexts[42].c_str() : defender->getCreature()->nameSing.c_str()); // creature perishes } } diff --git a/client/battle/CBattleInterfaceClasses.cpp b/client/battle/CBattleInterfaceClasses.cpp index b14a38651..1f64bee80 100644 --- a/client/battle/CBattleInterfaceClasses.cpp +++ b/client/battle/CBattleInterfaceClasses.cpp @@ -579,7 +579,7 @@ void CClickableHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) { char tabh[160]; const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl; - sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); + snprintf(tabh, 160, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); myInterface->console->alterTxt = std::string(tabh); setAlterText = true; } diff --git a/client/widgets/MiscWidgets.cpp b/client/widgets/MiscWidgets.cpp index 01c2fef54..01c9a927b 100644 --- a/client/widgets/MiscWidgets.cpp +++ b/client/widgets/MiscWidgets.cpp @@ -383,7 +383,7 @@ void MoraleLuckBox::set(const IBonusBearer *node) else { //it's a creature window - if ((morale && node->hasBonusOfType(Bonus::UNDEAD)) || + if ((morale && node && node->hasBonusOfType(Bonus::UNDEAD)) || node->hasBonusOfType(Bonus::BLOCK_MORALE) || node->hasBonusOfType(Bonus::NON_LIVING)) { text += CGI->generaltexth->arraytxt[113]; //unaffected by morale diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index 4ccd287aa..775e0ad36 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -1378,11 +1378,11 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes (const CStack case -WN: //-17 //left-up or right-up case WN + 1: //18 //right-down case -WN + 1: //-16 //right-up - BattleHex::checkAndPush (destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : -1 ), hexes); + BattleHex::checkAndPush (destinationTile.hex + pseudoVector + (((hex/WN)%2) ? 1 : -1 ), hexes); break; case WN-1: //16 //left-down case -WN-1: //-18 //left-up - BattleHex::checkAndPush (destinationTile.hex + pseudoVector + ((hex/WN)%2 ? 1 : 0), hexes); + BattleHex::checkAndPush (destinationTile.hex + pseudoVector + (((hex/WN)%2) ? 1 : 0), hexes); break; } for (BattleHex tile : hexes) @@ -1819,7 +1819,6 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell case CSpell::NEUTRAL: targetExists = true; break; - break; case CSpell::NEGATIVE: if(!casterStack || !ti.smart) { diff --git a/lib/Connection.cpp b/lib/Connection.cpp index 103108f0d..3452ddc18 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -478,7 +478,7 @@ std::vector CTypeList::castSequence(TypeInfoPtr from, Ty std::map previous; std::queue q; q.push(to); - while(q.size()) + while(!q.empty()) { auto typeNode = q.front(); q.pop(); diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index eca4fa46a..4ca573462 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -677,7 +677,7 @@ void CGBonusingObject::initObj() for (int i=0; i<6; i++) { info[i].limiter.dayOfWeek = i+1; - configureBonus(info[i], i%2 ? Bonus::MORALE : Bonus::LUCK, 1, 68); + configureBonus(info[i], (i%2) ? Bonus::MORALE : Bonus::LUCK, 1, 68); info[i].message.addTxt(MetaString::ADVOB_TXT, 62); soundID = soundBase::experience; } diff --git a/lib/rmg/CRmgTemplateZone.cpp b/lib/rmg/CRmgTemplateZone.cpp index a5dc76b19..cd8af623a 100644 --- a/lib/rmg/CRmgTemplateZone.cpp +++ b/lib/rmg/CRmgTemplateZone.cpp @@ -430,7 +430,7 @@ void CRmgTemplateZone::fractalize(CMapGenerator* gen) } assert (clearedTiles.size()); //this should come from zone connections - while (possibleTiles.size()) + while (!possibleTiles.empty()) { //link tiles in random order std::vector tilesToMakePath(possibleTiles.begin(), possibleTiles.end()); @@ -811,7 +811,7 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos, float } } - if (treasures.size()) + if (!treasures.empty()) { //find object closest to zone center, then connect it to the middle of the zone int3 closestFreeTile (-1,-1,-1); @@ -2000,7 +2000,7 @@ void CRmgTemplateZone::addAllPossibleObjects (CMapGenerator* gen) { creaturesAmount = boost::math::round(creaturesAmount / 5) * 5; } - else if (creaturesAmount <= 12) + else if (creaturesAmount <= 120) { creaturesAmount = boost::math::round(creaturesAmount / 10) * 10; } @@ -2070,12 +2070,16 @@ void CRmgTemplateZone::addAllPossibleObjects (CMapGenerator* gen) { case 1: school = spell->air; + break; case 2: school = spell->earth; + break; case 3: school = spell->fire; + break; case 4: school = spell->water; + break; } if (school) spells.push_back(spell); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index a3136a72f..c6779b6b2 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3389,7 +3389,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) break; } - if(destinationStack && stack->ID == destinationStack->ID) //we should just move, it will be handled by following check + if(destinationStack && stack && stack->ID == destinationStack->ID) //we should just move, it will be handled by following check { destinationStack = nullptr; } diff --git a/vcmibuilder b/vcmibuilder index 1d64abfb2..2b1dc6006 100755 --- a/vcmibuilder +++ b/vcmibuilder @@ -56,7 +56,7 @@ then # echo " --download " "Automatically download optional package using wget" # echo " " "Requires wget and Internet connection" # echo - echo " --dest DIRECTORY " "Path where resulting data will be placed. Default is ~/.vcmi" + echo " --dest DIRECTORY " "Path where resulting data will be placed. Default is ~/.local/share/vcmi" echo echo " --validate " "Run basic validness checks" exit 0