Selaa lähdekoodia

Fix several new issues detected by SonarCloud

Ivan Savenko 11 kuukautta sitten
vanhempi
sitoutus
aef6b0cc00

+ 2 - 2
client/renderSDL/RenderHandler.cpp

@@ -55,7 +55,7 @@ std::shared_ptr<CDefFile> RenderHandler::getAnimationFile(const AnimationPath &
 	return result;
 }
 
-std::optional<ResourcePath> RenderHandler::getPathForScaleFactor(ResourcePath path, std::string factor)
+std::optional<ResourcePath> RenderHandler::getPathForScaleFactor(const ResourcePath & path, const std::string & factor)
 {
 	if(path.getType() == EResType::IMAGE)
 	{
@@ -80,7 +80,7 @@ std::optional<ResourcePath> RenderHandler::getPathForScaleFactor(ResourcePath pa
 	return std::nullopt;
 }
 
-std::pair<ResourcePath, int> RenderHandler::getScalePath(ResourcePath p)
+std::pair<ResourcePath, int> RenderHandler::getScalePath(const ResourcePath & p)
 {
 	auto path = p;
 	int scaleFactor = 1;

+ 2 - 2
client/renderSDL/RenderHandler.h

@@ -29,8 +29,8 @@ class RenderHandler : public IRenderHandler
 	std::map<EFonts, std::shared_ptr<const IFont>> fonts;
 
 	std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
-	std::optional<ResourcePath> getPathForScaleFactor(ResourcePath path, std::string factor);
-	std::pair<ResourcePath, int> getScalePath(ResourcePath p);
+	std::optional<ResourcePath> getPathForScaleFactor(const ResourcePath & path, const std::string & factor);
+	std::pair<ResourcePath, int> getScalePath(const ResourcePath & p);
 	AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
 	void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);
 

+ 7 - 4
client/renderSDL/SDLImage.cpp

@@ -283,7 +283,10 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
 	if (factor <= 0)
 		throw std::runtime_error("Unable to scale by integer value of " + std::to_string(factor));
 
-	if (palette && surf && surf->format->palette)
+	if (!surf)
+		return shared_from_this();
+
+	if (palette && surf->format->palette)
 		SDL_SetSurfacePalette(surf, palette);
 
 	SDL_Surface * scaled = nullptr;
@@ -306,7 +309,7 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
 	// erase our own reference
 	SDL_FreeSurface(scaled);
 
-	if (surf && surf->format->palette)
+	if (surf->format->palette)
 		SDL_SetSurfacePalette(surf, originalPalette);
 
 	return ret;
@@ -314,8 +317,8 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
 
 std::shared_ptr<const ISharedImage> SDLImageShared::scaleTo(const Point & size, SDL_Palette * palette) const
 {
-	float scaleX = float(size.x) / fullSize.x;
-	float scaleY = float(size.y) / fullSize.y;
+	float scaleX = static_cast<float>(size.x) / fullSize.x;
+	float scaleY = static_cast<float>(size.y) / fullSize.y;
 
 	if (palette && surf->format->palette)
 		SDL_SetSurfacePalette(surf, palette);

+ 1 - 1
lib/CCreatureSet.cpp

@@ -725,7 +725,7 @@ int CStackInstance::getExpRank() const
 
 int CStackInstance::getLevel() const
 {
-	return std::max(1, static_cast<int>(getType()->getLevel()));
+	return std::max(1, getType()->getLevel());
 }
 
 void CStackInstance::giveStackExp(TExpType exp)

+ 2 - 2
lib/spells/CSpellHandler.cpp

@@ -544,8 +544,8 @@ void CSpell::serializeJson(JsonSerializeFormat & handler)
 ///CSpell::AnimationInfo
 CSpell::AnimationItem::AnimationItem() :
 	verticalPosition(VerticalPosition::TOP),
-	pause(0),
-	transparency(1)
+	transparency(1),
+	pause(0)
 {
 
 }

+ 1 - 1
server/battles/BattleActionProcessor.cpp

@@ -917,7 +917,7 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
 		handleAttackBeforeCasting(battle, ranged, attacker, defender);
 
 	// If the attacker or defender is not alive before the attack action, the action should be skipped.
-	if((attacker && !attacker->alive()) || (defender && !defender->alive()))
+	if((!attacker->alive()) || (defender && !defender->alive()))
 		return;
 
 	FireShieldInfo fireShield;