Skip to content

Commit

Permalink
Fix many Visual Studio compilation warnings (ihhub#3419)
Browse files Browse the repository at this point in the history
the stricter compilation the better code we have
  • Loading branch information
ihhub authored May 16, 2021
1 parent 3103180 commit ccc01c4
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 77 deletions.
2 changes: 1 addition & 1 deletion VisualStudio/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\src\engine;$(MSBuildThisFileDirectory)..\src\fheroes2\gui;$(MSBuildThisFileDirectory)..\src\fheroes2\maps;$(MSBuildThisFileDirectory)..\src\fheroes2\kingdom;$(MSBuildThisFileDirectory)..\src\fheroes2\campaign;$(MSBuildThisFileDirectory)..\src\fheroes2\game;$(MSBuildThisFileDirectory)..\src\fheroes2\dialog;$(MSBuildThisFileDirectory)..\src\fheroes2\system;$(MSBuildThisFileDirectory)..\src\fheroes2\spell;$(MSBuildThisFileDirectory)..\src\fheroes2\monster;$(MSBuildThisFileDirectory)..\src\fheroes2\castle;$(MSBuildThisFileDirectory)..\src\fheroes2\agg;$(MSBuildThisFileDirectory)..\src\fheroes2\heroes;$(MSBuildThisFileDirectory)..\src\fheroes2\resource;$(MSBuildThisFileDirectory)..\src\fheroes2\ai;$(MSBuildThisFileDirectory)..\src\fheroes2\army;$(MSBuildThisFileDirectory)..\src\fheroes2\battle;$(MSBuildThisFileDirectory)..\src\fheroes2\pocketpc;$(MSBuildThisFileDirectory)..\src\fheroes2\objects;$(MSBuildThisFileDirectory)..\src\fheroes2\world;$(MSBuildThisFileDirectory)..\src\fheroes2\image;$(MSBuildThisFileDirectory)..\src\thirdparty\libsmacker;$(MSBuildThisFileDirectory)packages\installed\zlib\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;WITH_ZLIB;WITH_MIXER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatSpecificWarningsAsErrors>4018;4100;4189;4309;4319;4389;4592;4702;4715;4800</TreatSpecificWarningsAsErrors>
<TreatSpecificWarningsAsErrors>4018;4028;4100;4189;4245;4309;4319;4389;4592;4702;4706;4715;4800</TreatSpecificWarningsAsErrors>
</ClCompile>
<ResourceCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\src\fheroes2\system;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand Down
8 changes: 4 additions & 4 deletions src/engine/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ namespace fheroes2
copy( image_ );
}

Image::Image( Image && image_ )
Image::Image( Image && image_ ) noexcept
: _width( 0 )
, _height( 0 )
, _data( std::move( image_._data ) )
Expand All @@ -431,7 +431,7 @@ namespace fheroes2
return *this;
}

Image & Image::operator=( Image && image_ )
Image & Image::operator=( Image && image_ ) noexcept
{
if ( this != &image_ ) {
// We shouldn't copy or move different types of images.
Expand Down Expand Up @@ -552,7 +552,7 @@ namespace fheroes2
, _y( sprite._y )
{}

Sprite::Sprite( Sprite && sprite )
Sprite::Sprite( Sprite && sprite ) noexcept
: Image( std::move( sprite ) )
, _x( 0 )
, _y( 0 )
Expand All @@ -573,7 +573,7 @@ namespace fheroes2
return *this;
}

Sprite & Sprite::operator=( Sprite && sprite )
Sprite & Sprite::operator=( Sprite && sprite ) noexcept
{
if ( this != &sprite ) {
Image::operator=( std::move( sprite ) );
Expand Down
8 changes: 4 additions & 4 deletions src/engine/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ namespace fheroes2
public:
Image( int32_t width_ = 0, int32_t height_ = 0 );
Image( const Image & image_ );
Image( Image && image_ );
Image( Image && image_ ) noexcept;

virtual ~Image() = default;

Image & operator=( const Image & image_ );
Image & operator=( Image && image_ );
Image & operator=( Image && image_ ) noexcept;

virtual void resize( int32_t width_, int32_t height_ );

Expand Down Expand Up @@ -102,12 +102,12 @@ namespace fheroes2
Sprite( int32_t width_ = 0, int32_t height_ = 0, int32_t x_ = 0, int32_t y_ = 0 );
Sprite( const Image & image, int32_t x_ = 0, int32_t y_ = 0 );
Sprite( const Sprite & sprite );
Sprite( Sprite && sprite );
Sprite( Sprite && sprite ) noexcept;

~Sprite() override = default;

Sprite & operator=( const Sprite & sprite );
Sprite & operator=( Sprite && sprite );
Sprite & operator=( Sprite && sprite ) noexcept;

int32_t x() const
{
Expand Down
2 changes: 1 addition & 1 deletion src/engine/image_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace

namespace fheroes2
{
bool Save( const Image & image, const std::string & path, uint8_t background )
bool Save( const Image & image, const std::string & path, const uint8_t background )
{
if ( image.empty() || path.empty() )
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/image_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace fheroes2
{
bool Save( const Image & image, const std::string & path );

// Save an image into file. 'background' represents palette index from the original palette. Default value is 23.
bool Save( const Image & image, const std::string & path, uint8_t background );
// Save an image into file. 'background' represents palette index from the original palette. Recommended value is 23.
bool Save( const Image & image, const std::string & path, const uint8_t background );

bool Load( const std::string & path, Image & image );

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/ai/normal/ai_normal_castle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace AI
const bool islandOrPeninsula = neighbourRegions < 3;

// force building a shipyard, +1 to cost check since we can have 0 neighbours
if ( islandOrPeninsula && BuildIfEnoughResources( castle, BUILD_SHIPYARD, neighbourRegions + 1 ) ) {
if ( islandOrPeninsula && BuildIfEnoughResources( castle, BUILD_SHIPYARD, static_cast<uint32_t>( neighbourRegions + 1 ) ) ) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/army/army_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void RedistributeArmy( ArmyTroop & troopFrom, ArmyTroop & troopTarget, Army * ar
}
}
else {
uint32_t freeSlots = 1 + armyTarget->Size() - armyTarget->GetCount();
uint32_t freeSlots = static_cast<uint32_t>( 1 + armyTarget->Size() - armyTarget->GetCount() );

if ( isSameTroopType )
++freeSlots;
Expand Down
9 changes: 4 additions & 5 deletions src/fheroes2/dialog/dialog_marketplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ class TradeWindowGUI
textSell.SetFont( Font::SMALL );
textBuy.SetFont( Font::SMALL );

const std::vector<Player *> players = conf.GetPlayers();
const Players & players = conf.GetPlayers();
int playerCount = 0;
for ( Players::const_iterator it = players.begin(); it != players.end(); ++it ) {
if ( *it ) {
const Player & player = ( **it );
const Kingdom & kingdom = world.GetKingdom( player.GetColor() );
for ( const Player * player : players ) {
if ( player != nullptr ) {
const Kingdom & kingdom = world.GetKingdom( player->GetColor() );
if ( kingdom.isPlay() )
++playerCount;
}
Expand Down
6 changes: 3 additions & 3 deletions src/fheroes2/game/game_campaign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace
// available scenario (one of which should be selected)
if ( std::find( availableMaps.begin(), availableMaps.end(), scenarioID ) != availableMaps.end() ) {
buttonGroup.createButton( trackOffset.x + x, trackOffset.y + y, fheroes2::AGG::GetICN( iconsId, Campaign::SCENARIOICON_AVAILABLE ),
fheroes2::AGG::GetICN( iconsId, selectedIconIdx ), i );
fheroes2::AGG::GetICN( iconsId, selectedIconIdx ), static_cast<int>( i ) );
}
// cleared scenario
else if ( std::find( clearedMaps.begin(), clearedMaps.end(), static_cast<int>( i ) ) != clearedMaps.end() ) {
Expand Down Expand Up @@ -154,7 +154,7 @@ namespace
const int textChoiceWidth = 150;
for ( size_t i = 0; i < bonuses.size(); ++i ) {
Text choice( bonuses[i].ToString(), Font::BIG );
choice.Blit( top.x + 425, top.y + 209 + 22 * i - choice.h() / 2, textChoiceWidth );
choice.Blit( top.x + 425, top.y + 209 + 22 * static_cast<int>( i ) - choice.h() / 2, textChoiceWidth );
}
}

Expand All @@ -174,7 +174,7 @@ namespace
else // if we have exactly 4 obtained awards, display the fourth award, otherwise show "and more..."
award.Set( awardCount == 4 ? obtainedAwards[i].ToString() : std::string( _( "and more..." ) ), Font::BIG );

award.Blit( top.x + 425, top.y + 100 + yOffset * i - award.h() / 2, textAwardWidth );
award.Blit( top.x + 425, top.y + 100 + yOffset * static_cast<int>( i ) - award.h() / 2, textAwardWidth );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/game/game_loadgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ int Game::LoadGame( void )
const int32_t buttonYStep = 66;

for ( size_t i = 0; i < buttonCount - 1; ++i ) {
buttons[i].setPosition( buttonXPos, buttonYPos + buttonYStep * i );
buttons[i].setPosition( buttonXPos, buttonYPos + buttonYStep * static_cast<int32_t>( i ) );
buttons[i].draw();
}

Expand Down
46 changes: 24 additions & 22 deletions src/fheroes2/gui/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,21 @@ int TextAscii::FontHeight( const int f )
return 13 + 3 + 1;
}

int TextAscii::w( u32 s, u32 c ) const
int TextAscii::w( size_t s, size_t c ) const
{
uint32_t res = 0;
uint32_t size = message.size();
const size_t size = message.size();
if ( size == 0 )
return 0;

int res = 0;

if ( size ) {
if ( s > size - 1 )
s = size - 1;
if ( !c || c > size )
c = size - s;
if ( s > size - 1 )
s = size - 1;
if ( !c || c > size )
c = size - s;

for ( uint32_t i = s; i < s + c; ++i )
res += CharWidth( static_cast<uint8_t>( message[i] ), font );
}
for ( size_t i = s; i < s + c; ++i )
res += CharWidth( static_cast<uint8_t>( message[i] ), font );

return res;
}
Expand Down Expand Up @@ -271,20 +272,21 @@ int TextUnicode::CharHeight( int f )
return isSmallFont( f ) ? ( AGG::GetFontHeight( true ) + 2 ) : ( AGG::GetFontHeight( false ) + 8 );
}

int TextUnicode::w( u32 s, u32 c ) const
int TextUnicode::w( size_t s, size_t c ) const
{
u32 res = 0;
u32 size = message.size();
const size_t size = message.size();
if ( size == 0 )
return 0;

int res = 0;

if ( size ) {
if ( s > size - 1 )
s = size - 1;
if ( !c || c > size )
c = size - s;
if ( s > size - 1 )
s = size - 1;
if ( !c || c > size )
c = size - s;

for ( u32 ii = s; ii < s + c; ++ii )
res += CharWidth( message[ii], font );
}
for ( size_t ii = s; ii < s + c; ++ii )
res += CharWidth( message[ii], font );

return res;
}
Expand Down
22 changes: 11 additions & 11 deletions src/fheroes2/gui/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class TextInterface
virtual void SetFont( int ) = 0;
virtual void Clear( void ) = 0;

virtual int w( void ) const = 0;
virtual int h( void ) const = 0;
virtual size_t Size( void ) const = 0;
virtual int w() const = 0;
virtual int h() const = 0;
virtual size_t Size() const = 0;

virtual void Blit( s32, s32, int maxw, fheroes2::Image & sf = fheroes2::Display::instance() ) = 0;

Expand All @@ -82,11 +82,11 @@ class TextAscii : public TextInterface
void SetFont( int ) override;
void Clear( void ) override;

int w( void ) const override;
int h( void ) const override;
int w() const override;
int h() const override;
size_t Size( void ) const override;

int w( u32, u32 ) const;
int w( size_t s, size_t c ) const;
int h( int ) const;

void Blit( s32, s32, int maxw, fheroes2::Image & sf = fheroes2::Display::instance() ) override;
Expand All @@ -109,11 +109,11 @@ class TextUnicode : public TextInterface
void SetFont( int ) override;
void Clear( void ) override;

int w( void ) const override;
int h( void ) const override;
int w() const override;
int h() const override;
size_t Size( void ) const override;

int w( u32, u32 ) const;
int w( size_t s, size_t c ) const;
int h( int ) const;

void Blit( s32, s32, int maxw, fheroes2::Image & sf = fheroes2::Display::instance() ) override;
Expand Down Expand Up @@ -189,8 +189,8 @@ class TextSprite : protected Text
bool isHide( void ) const;
bool isShow( void ) const;

int w( void ) const;
int h( void ) const;
int w() const;
int h() const;

fheroes2::Rect GetRect( void ) const;

Expand Down
12 changes: 8 additions & 4 deletions src/thirdparty/libsmacker/smacker.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ smk smk_open_memory(const unsigned char* buffer, const unsigned long size)
/* set up the read union for Memory mode */
fp.ram = (unsigned char*)buffer;

if (!(s = smk_open_generic(0,fp,size,SMK_MODE_MEMORY)))
s = smk_open_generic(0,fp,size,SMK_MODE_MEMORY);
if (!s)
{
fprintf(stderr,"libsmacker::smk_open_memory(buffer,%lu) - ERROR: Fatal error in smk_open_generic, returning NULL.\n",size);
}
Expand All @@ -449,7 +450,8 @@ smk smk_open_filepointer(FILE* file, const unsigned char mode)
/* Copy file ptr to internal union */
fp.file = file;

if (!(s = smk_open_generic(1,fp,0,mode)))
s = smk_open_generic(1,fp,0,mode);
if (!s)
{
fprintf(stderr,"libsmacker::smk_open_filepointer(file,%u) - ERROR: Fatal error in smk_open_generic, returning NULL.\n",mode);
fclose(fp.file);
Expand Down Expand Up @@ -477,7 +479,8 @@ smk smk_open_file(const char* filename, const unsigned char mode)

smk_assert(filename);

if (!(fp = fopen(filename,"rb")))
fp = fopen(filename,"rb");
if (!fp)
{
fprintf(stderr,"libsmacker::smk_open_file(%s,%u) - ERROR: could not open file (errno: %d)\n",filename,mode,errno);
perror ("\tError reported was");
Expand Down Expand Up @@ -1222,7 +1225,8 @@ static char smk_render(smk s)
smk_assert(s);

/* Retrieve current chunk_size for this frame. */
if (!(i = s->chunk_size[s->cur_frame]))
i = s->chunk_size[s->cur_frame];
if (!i)
{
fprintf(stderr,"libsmacker::smk_render(s) - Warning: frame %lu: chunk_size is 0.\n",s->cur_frame);
goto error;
Expand Down
16 changes: 8 additions & 8 deletions src/thirdparty/libsmacker/smacker.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ extern "C" {

/* OPEN OPERATIONS */
/** open an smk (from a file) */
smk smk_open_file(const char* filename, unsigned char mode);
smk smk_open_file(const char* filename, const unsigned char mode);
/** open an smk (from a file pointer) */
smk smk_open_filepointer(FILE* file, unsigned char mode);
smk smk_open_filepointer(FILE* file, const unsigned char mode);
/** read an smk (from a memory buffer) */
smk smk_open_memory(const unsigned char* buffer, unsigned long size);
smk smk_open_memory(const unsigned char* buffer, const unsigned long size);

/* CLOSE OPERATIONS */
/** close out an smk file and clean up memory */
Expand All @@ -76,18 +76,18 @@ char smk_info_video(const smk object, unsigned long* w, unsigned long* h, unsign
char smk_info_audio(const smk object, unsigned char* track_mask, unsigned char channels[7], unsigned char bitdepth[7], unsigned long audio_rate[7]);

/* ENABLE/DISABLE Switches */
char smk_enable_all(smk object, unsigned char mask);
char smk_enable_video(smk object, unsigned char enable);
char smk_enable_audio(smk object, unsigned char track, unsigned char enable);
char smk_enable_all(smk object, const unsigned char mask);
char smk_enable_video(smk object, const unsigned char enable);
char smk_enable_audio(smk object, const unsigned char track, const unsigned char enable);

/** Retrieve palette */
const unsigned char* smk_get_palette(const smk object);
/** Retrieve video frame, as a buffer of size w*h */
const unsigned char* smk_get_video(const smk object);
/** Retrieve decoded audio chunk, track N */
const unsigned char* smk_get_audio(const smk object, unsigned char track);
const unsigned char* smk_get_audio(const smk object, const unsigned char track);
/** Get size of currently pointed decoded audio chunk, track N */
unsigned long smk_get_audio_size(const smk object, unsigned char track);
unsigned long smk_get_audio_size(const smk object, const unsigned char track);

/** rewind to first frame and unpack */
char smk_first(smk object);
Expand Down
4 changes: 2 additions & 2 deletions src/thirdparty/libsmacker/smk_bitstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct smk_bit_t* smk_bs_init(const unsigned char* b, const unsigned long size)
Returns -1 if error encountered */
char _smk_bs_read_1(struct smk_bit_t* bs)
{
unsigned char ret = -1;
unsigned char ret = (unsigned char)-1;

/* sanity check */
smk_assert(bs);
Expand Down Expand Up @@ -90,7 +90,7 @@ char _smk_bs_read_1(struct smk_bit_t* bs)
Returns -1 if error. */
short _smk_bs_read_8(struct smk_bit_t* bs)
{
unsigned char ret = -1;
unsigned char ret = (unsigned char)-1;

/* sanity check */
smk_assert(bs);
Expand Down
2 changes: 1 addition & 1 deletion src/thirdparty/libsmacker/smk_bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct smk_bit_t;

/* BITSTREAM Functions */
/** Initialize a bitstream */
struct smk_bit_t* smk_bs_init(const unsigned char* b, unsigned long size);
struct smk_bit_t* smk_bs_init(const unsigned char* b, const unsigned long size);

/** This macro checks return code from _smk_bs_read_1 and
jumps to error label if problems occur. */
Expand Down
Loading

0 comments on commit ccc01c4

Please sign in to comment.