-
Notifications
You must be signed in to change notification settings - Fork 55
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
base: vanilla
Are you sure you want to change the base?
Fix some warnings #984
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should take the |
||
curbuf += 4; | ||
memcpy(&field->DataType, curbuf, 2); | ||
curbuf += 2; | ||
memcpy(&field->Size, curbuf, 2); | ||
curbuf += 2; | ||
remaining_size -= FIELD_HEADER_SIZE; | ||
|
||
// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use ARRAY_SIZE, defined in common/macros.h |
||
Random[i] = RandomClass(); | ||
} | ||
} | ||
|
||
/*********************************************************************************************** | ||
|
@@ -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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -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; | ||
} | ||
|
@@ -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)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
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.