Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some warnings #984

Open
wants to merge 1 commit into
base: vanilla
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if(NOT MSVC)
set(CMAKE_FIND_FRAMEWORK "LAST")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -Wwrite-strings -Werror=write-strings -fcheck-new -fsigned-char -fdata-sections -ffunction-sections -DNOMINMAX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -Wformat -Wwrite-strings -Werror=write-strings -fcheck-new -fsigned-char -DNOMINMAX")
else()
set(CMAKE_CXX_FLAGS "/Zc:strictStrings")
endif()
Expand Down
2 changes: 1 addition & 1 deletion common/blowpipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int BlowPipe::Put(void const* source, int slen)
** Process the input data in blocks until there is not enough
** source data to fill a full block of data.
*/
while (slen >= sizeof(Buffer)) {
while (slen >= (int)sizeof(Buffer)) {
if (Control == DECRYPT) {
BF->Decrypt(source, sizeof(Buffer), Buffer);
} else {
Expand Down
1 change: 0 additions & 1 deletion common/cdfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ extern int Get_CD_Index(int cd_drive, int timeout);
*=============================================================================================*/
int Is_Disk_Inserted(int disk)
{
disk;
return true;
}

Expand Down
6 changes: 2 additions & 4 deletions common/fading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

void* Build_Fading_Table(void const* palette, void* dest, int color, int frac)
{
const int ALLOWED_COUNT = 16;
const int ALLOWED_START = 256 - ALLOWED_COUNT;
// const int ALLOWED_COUNT = 16;
// const int ALLOWED_START = 256 - ALLOWED_COUNT;

if (!palette || !dest) {
return 0;
Expand All @@ -32,7 +32,6 @@ void* Build_Fading_Table(void const* palette, void* dest, int color, int frac)
unsigned char targetred = pal[palindex++];
unsigned char targetgreen = pal[palindex++];
unsigned char targetblue = pal[palindex];
unsigned tableindex = 0;
dst[0] = 0;

// Remap most pal entries to the last 16 entries that are the most faded colours.
Expand Down Expand Up @@ -107,7 +106,6 @@ void* Conquer_Build_Fading_Table(const void* palette, void* dest, int color, int
unsigned char targetred = pal[palindex++];
unsigned char targetgreen = pal[palindex++];
unsigned char targetblue = pal[palindex];
unsigned tableindex = 0;
dst[0] = 0;

// Remap most pal entries to the last 16 entries that are the most faded colours.
Expand Down
2 changes: 1 addition & 1 deletion common/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void Resolve_File(char* fname)
#ifndef _WIN32
// step through each sub-directory before going for the win
char* next = fname;
while (next = strchr(next, '/')) {
while ((next = strchr(next, '/')) != NULL) {
*next = '\0';
Resolve_File_Single(fname);
*next++ = '/';
Expand Down
11 changes: 8 additions & 3 deletions common/filepcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ GraphicBufferClass* Read_PCX_File(const char* name, char* palette, void* Buff, i
if (rle > 192) {
rle -= 192;
color = READ_CHAR();
;
#ifdef __GNUC__
// FIXME: same code below does not give warning???
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif
memset(buffer + scan_pos + i, color, rle);
i += rle;
} else {
Expand All @@ -146,10 +149,12 @@ GraphicBufferClass* Read_PCX_File(const char* name, char* palette, void* Buff, i
}
}

if (i == width)
if (i == (unsigned)width) {
rle = READ_CHAR();
if (rle > 192)
}
if (rle > 192) {
rle = READ_CHAR();
}

} else {

Expand Down
1 change: 0 additions & 1 deletion common/keyframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ uintptr_t Build_Frame(void const* dataptr, unsigned short framenumber, void* buf
char frameflags;
uintptr_t return_value;
char* temp_shape_ptr;
unsigned short keyfr_frames;
int i;

//
Expand Down
2 changes: 1 addition & 1 deletion common/linear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ bool Linear_Scale_To_Linear(void* thisptr,
int xrat = 0;

for (int j = 0; j < dst_x1; ++j) {
*d++ = (remap)[s[xrat >> 16]];
*d++ = (remap)[(unsigned char)s[xrat >> 16]];
xrat += x_ratio;
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/listnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class GenericNode
}
bool Is_Valid(void) const
{
return (this != NULL && NextNode != NULL && PrevNode != NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually seems to be something intended by the original programmers rather than a programming error. Are you sure this is actually not necessary?

For example, if you call ->Is_Valid() with a nullptr object this function will return false rather than crashing the code.

return (NextNode != NULL && PrevNode != NULL);
}

protected:
Expand Down
8 changes: 4 additions & 4 deletions common/mixfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ template <class T, class TCRC> MixFileClass<T, TCRC>::~MixFileClass(void)
*=============================================================================================*/
template <class T, class TCRC>
MixFileClass<T, TCRC>::MixFileClass(char const* filename)
: IsDigest(false)
: Filename(0)
, IsDigest(false)
, IsEncrypted(false)
, IsAllocated(false)
, Filename(0)
, Count(0)
, DataSize(0)
, DataStart(0)
Expand Down Expand Up @@ -297,7 +297,7 @@ MixFileClass<T, TCRC>::MixFileClass(char const* filename)
** whether this is an extended mixfile format or the plain format. An
** extended format may have extra options or data layout.
*/
int got = straw->Get(&alternate, sizeof(alternate));
straw->Get(&alternate, sizeof(alternate));
int16_t alternate_first = le16toh(alternate.First);
int16_t alternate_second = le16toh(alternate.Second);

Expand Down Expand Up @@ -422,7 +422,7 @@ MixFileClass<T, TCRC>::MixFileClass(char const* filename, PKey const* key)
** whether this is an extended mixfile format or the plain format. An
** extended format may have extra options or data layout.
*/
int got = straw->Get(&alternate, sizeof(alternate));
straw->Get(&alternate, sizeof(alternate));
int16_t alternate_first = le16toh(alternate.First);
int16_t alternate_second = le16toh(alternate.Second);

Expand Down
4 changes: 2 additions & 2 deletions common/mp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ bool XMP_Sub(uint16_t* result,
#ifdef __BIG_ENDIAN__
uint16_t temp_left_number[precision * 2];
uint16_t temp_result[precision * 2];
size_t i;
int i;

for (i = 0; i < precision * 2; i++) {
Set_HalfWord(temp_left_number, i, Get_HalfWord(left_number, left_number_offset + i));
Expand Down Expand Up @@ -2420,7 +2420,7 @@ bool XMP_Rabin_Miller_Test(Straw& rng, digit const* w, int rounds, int precision
return false;
}
}
if (j == a) {
if (j == (int)a) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/mp.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ inline bool XMP_Is_Negative(const digit* r, int precision)
return ((signeddigit) * (r + (precision - 1)) < 0);
}

inline bool XMP_Test_Eq_Int(digit const* r, int i, int p)
inline bool XMP_Test_Eq_Int(digit const* r, digit i, int p)
{
return ((*r == i) && XMP_Significance(r, p) <= 1);
}
Expand Down
8 changes: 6 additions & 2 deletions common/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ PacketClass::PacketClass(char* curbuf)
//
// Copy the adjusted header into the buffer and then advance the buffer
//
memcpy(field, curbuf, FIELD_HEADER_SIZE);
curbuf += FIELD_HEADER_SIZE;
memcpy(field->ID, curbuf, 4);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take the sizeof(field->ID) rather than hardcoding it to 4. If we decide later to change this in the future this memcpy would be very error prone.

curbuf += 4;
memcpy(&field->DataType, curbuf, 2);
curbuf += 2;
memcpy(&field->Size, curbuf, 2);
curbuf += 2;
remaining_size -= FIELD_HEADER_SIZE;

//
Expand Down
5 changes: 3 additions & 2 deletions common/palettec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ PaletteClass& PaletteClass::operator=(PaletteClass const& palette)
if (this == &palette)
return (*this);

memcpy(&Palette[0], &palette.Palette[0], sizeof(Palette));
for (int i = 0; i < PaletteClass::COLOR_COUNT; i++)
Palette[i] = palette.Palette[i];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is replacing a very optimized copy of palettes with a potentially non-optimized one. Are you sure this is necessary?

return (*this);
}

Expand Down Expand Up @@ -319,7 +320,7 @@ void PaletteClass::Set(int time, void (*callback)(void)) const
** code, at the time of this writing, delays at least one game tick in the process
** of setting the palette.
*/
int holdtime = timer;
unsigned int holdtime = timer;

/*
** Set the palette to this intermediate palette and then loop back
Expand Down
2 changes: 0 additions & 2 deletions common/pk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ void PKey::Decode_Exponent(void* buffer)
void PKey::Generate(Straw& random, int bits, PKey& fastkey, PKey& slowkey)
{
// PG_TO_FIX
fastkey;
slowkey;
#if (0)
/*
** Key generation consists of create a key pair and then testing the key
Expand Down
2 changes: 1 addition & 1 deletion common/rawfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ RawFileClass::RawFileClass(char const* filename)
: Rights(0)
, BiasStart(0)
, BiasLength(-1)
, Handle(nullptr)
, Filename(nullptr)
, Handle(nullptr)
{
Set_Name(filename);
}
Expand Down
2 changes: 1 addition & 1 deletion common/rawfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ inline RawFileClass::RawFileClass(void)
: Rights(READ)
, BiasStart(0)
, BiasLength(-1)
, Handle(nullptr)
, Filename(0)
, Handle(nullptr)
{
}

Expand Down
10 changes: 6 additions & 4 deletions common/rndstraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ void RandomStraw::Reset(void)
{
SeedBits = 0;
Current = 0;
memset(Random, '\0', sizeof(Random));
for (size_t i = 0; i < sizeof(Random) / sizeof(Random[0]); i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ARRAY_SIZE, defined in common/macros.h

Random[i] = RandomClass();
}
}

/***********************************************************************************************
Expand Down Expand Up @@ -210,7 +212,7 @@ void RandomStraw::Seed_Byte(char seed)
*=============================================================================================*/
void RandomStraw::Seed_Short(short seed)
{
for (int index = 0; index < (sizeof(seed) * CHAR_BIT); index++) {
for (int index = 0; index < ((int)sizeof(seed) * CHAR_BIT); index++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size_t may be cleaner than int here

Seed_Bit(seed);
seed >>= 1;
}
Expand All @@ -232,7 +234,7 @@ void RandomStraw::Seed_Short(short seed)
*=============================================================================================*/
void RandomStraw::Seed_Long(int seed)
{
for (int index = 0; index < (sizeof(seed) * CHAR_BIT); index++) {
for (int index = 0; index < ((int)sizeof(seed) * CHAR_BIT); index++) {
Seed_Bit(seed);
seed >>= 1;
}
Expand Down Expand Up @@ -260,7 +262,7 @@ void RandomStraw::Scramble_Seed(void)
{
SHAEngine sha;

for (int index = 0; index < sizeof(Random); index++) {
for (int index = 0; index < (int)sizeof(Random); index++) {
char digest[20];

sha.Hash(&Random[0], sizeof(Random));
Expand Down
7 changes: 4 additions & 3 deletions common/video_sdl1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,15 @@ class VideoSurfaceSDL1 : public VideoSurface

virtual void Blt(const Rect& destRect, VideoSurface* src, const Rect& srcRect, bool mask)
{
SDL_Rect srcRectSDL = {srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height};
SDL_Rect destRectSDL = {destRect.X, destRect.Y, destRect.Width, destRect.Height};
SDL_Rect srcRectSDL = {Sint16(srcRect.X), Sint16(srcRect.Y), Uint16(srcRect.Width), Uint16(srcRect.Height)};
SDL_Rect destRectSDL = {
Sint16(destRect.X), Sint16(destRect.Y), Uint16(destRect.Width), Uint16(destRect.Height)};
SDL_BlitSurface(((VideoSurfaceSDL1*)src)->surface, &srcRectSDL, surface, &destRectSDL);
}

virtual void FillRect(const Rect& rect, unsigned char color)
{
SDL_Rect rectSDL = {rect.X, rect.Y, rect.Width, rect.Height};
SDL_Rect rectSDL = {Sint16(rect.X), Sint16(rect.Y), Uint16(rect.Width), Uint16(rect.Height)};
SDL_FillRect(surface, &rectSDL, color);
}

Expand Down
17 changes: 5 additions & 12 deletions common/vqaloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ typedef void (*UnVQFuncPtr)(uint8_t*, uint8_t*, uint8_t*, unsigned, unsigned, un
#define CHUNK_WVQA MAKE_CHUNK('W', 'V', 'Q', 'A')

// name (vqa encoder name and date string) chunk.
#define CHUNK_NAME \
MAKE_CHUNK('N', \
'A', \
'M', \
'E') // Standard IFF Name chunk used in Poly,BR and LOL game VQA's, poly contains the string \
// "Generated by BuildVQA 3.9 (03/03/95)"
// Standard IFF Name chunk used in Poly,BR and LOL game VQA's, poly contains the string
// "Generated by BuildVQA 3.9 (03/03/95)"
#define CHUNK_NAME MAKE_CHUNK('N', 'A', 'M', 'E')

// sound chunks.
#define CHUNK_SND0 MAKE_CHUNK('S', 'N', 'D', '0') // PCM Audio
Expand Down Expand Up @@ -117,12 +114,8 @@ typedef void (*UnVQFuncPtr)(uint8_t*, uint8_t*, uint8_t*, unsigned, unsigned, un
#define CHUNK_VQFL MAKE_CHUNK('V', 'Q', 'F', 'L') // Vector Quantized Frame Loop used in LOL3 and BR
#define CHUNK_CBFZ MAKE_CHUNK('C', 'B', 'F', 'Z')

#define CHUNK_CAP0 \
MAKE_CHUNK( \
'C', \
'A', \
'P', \
'0') // Isn't in any VQA's, present in early TD code, captions(subtitles) where in there compressed with LCW
// Isn't in any VQA's, present in early TD code, captions(subtitles) where in there compressed with LCW
#define CHUNK_CAP0 MAKE_CHUNK('C', 'A', 'P', '0')
#define CHUNK_EVA0 MAKE_CHUNK('E', 'V', 'A', '0') // Present in early TD code, purpose unknown

// Not found in any VQAs
Expand Down
2 changes: 1 addition & 1 deletion common/wwstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ inline static void _splitpath(const char* path, char* drive, char* dir, char* fn
return;
}

for (int i = 0; i < strlen(path); i++) {
for (int i = 0; i < (int)strlen(path); i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid calling strlen in a loop comparison like this. This is O(n²) instead of O(n). Instead store the size of the string into a variable and use that instead.

if (path[i] == '.') {
strcpy(ext, path + i + 1);
break;
Expand Down
2 changes: 1 addition & 1 deletion redalert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,4 @@ if(BUILD_VANILLARA)
-g3 -fno-omit-frame-pointer)
target_link_options(VanillaRA PUBLIC -fsanitize=address)
endif()
endif()
endif()
6 changes: 6 additions & 0 deletions redalert/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2363,9 +2363,15 @@ bool CellClass::Goodie_Check(FootClass* object)
ucount += hptr->QuantityV(j);
}
int bcount = 0;
#ifdef FIXIT_ANTS
for (j = 0; j < STRUCT_COUNT - 3; j++) {
bcount += hptr->QuantityB(j);
}
#else
for (j = 0; j < STRUCT_COUNT; j++) {
bcount += hptr->QuantityB(j);
}
#endif
ucount += bcount / 2; // weight buildings less
minunits = min(minunits, ucount);
}
Expand Down
4 changes: 2 additions & 2 deletions redalert/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ void Debug_Key(unsigned input)
* HISTORY: *
* 07/18/1996 JLB : Created. *
*=============================================================================================*/
#if 0
static char const* Bench_Time(BenchType btype)
{
#if 0
static char buffer[32];

int rootcount = Benches[BENCH_GAME_FRAME].Count();
Expand All @@ -368,8 +368,8 @@ static char const* Bench_Time(BenchType btype)
percent = 99;
sprintf(buffer, "%-2d%% %7d", percent, time);
return (buffer);
#endif
}
#endif

/***********************************************************************************************
* Benchmarks -- Display the performance tracking benchmarks. *
Expand Down
Loading
Loading