Defensive casting to silence clang warnings

This commit is contained in:
Michael Martin
2020-06-09 18:18:12 -07:00
parent 76bc15156f
commit 4f393ac170
4 changed files with 29 additions and 23 deletions
+22 -16
View File
@@ -68,7 +68,7 @@ read_16 (void *fp, UWORD *v)
static inline size_t
read_16s (void *fp, SWORD *v)
{
return read_16 (fp, v);
return read_16 (fp, (UWORD *) v);
}
static inline size_t
@@ -93,7 +93,7 @@ read_32 (void *fp, DWORD *v)
static inline size_t
read_32s (void *fp, SDWORD *v)
{
return read_32 (fp, v);
return read_32 (fp, (DWORD *) v);
}
static inline size_t
@@ -103,6 +103,12 @@ read_a8 (void *fp, BYTE *ar, COUNT count)
return ReadResFile (ar, 1, count, fp) == count;
}
static inline size_t
read_a8s (void *fp, char *ar, COUNT count)
{
return read_a8(fp, (BYTE *) ar, count);
}
static inline size_t
skip_8 (void *fp, COUNT count)
{
@@ -381,7 +387,7 @@ LoadSisState (SIS_STATE *SSPtr, void *fp)
static BOOLEAN
LoadSummary (SUMMARY_DESC *SummPtr, void *fp)
{
SDWORD magic;
DWORD magic;
DWORD nameSize = 0;
if (!read_32s (fp, &magic))
return FALSE;
@@ -417,14 +423,14 @@ LoadSummary (SUMMARY_DESC *SummPtr, void *fp)
if (nameSize < SAVE_NAME_SIZE)
{
if (read_a8 (fp, SummPtr->SaveName, nameSize) != 1)
if (read_a8s (fp, SummPtr->SaveName, nameSize) != 1)
return FALSE;
SummPtr->SaveName[nameSize] = 0;
}
else
{
DWORD remaining = nameSize - SAVE_NAME_SIZE + 1;
if (read_a8 (fp, SummPtr->SaveName, SAVE_NAME_SIZE-1) != 1)
if (read_a8s (fp, SummPtr->SaveName, SAVE_NAME_SIZE-1) != 1)
return FALSE;
SummPtr->SaveName[SAVE_NAME_SIZE-1] = 0;
if (skip_8 (fp, remaining) != 1)
@@ -486,17 +492,17 @@ LoadGroupList (uio_Stream *fh, DWORD chunksize)
{
BYTE race_outer;
IP_GROUP ip;
read_8 (fh, &race_outer);
read_16 (fh, &ip.group_counter);
read_8 (fh, &ip.race_id);
read_8 (fh, &ip.sys_loc);
read_8 (fh, &ip.task);
read_8 (fh, &ip.in_system);
read_8 (fh, &ip.dest_loc);
read_8 (fh, &ip.orbit_pos);
read_8 (fh, &ip.group_id);
read_16 (fh, &ip.loc.x);
read_16 (fh, &ip.loc.y);
read_8 (fh, &race_outer);
read_16 (fh, &ip.group_counter);
read_8 (fh, &ip.race_id);
read_8 (fh, &ip.sys_loc);
read_8 (fh, &ip.task);
read_8 (fh, &ip.in_system);
read_8 (fh, &ip.dest_loc);
read_8 (fh, &ip.orbit_pos);
read_8 (fh, &ip.group_id);
read_16s (fh, &ip.loc.x);
read_16s (fh, &ip.loc.y);
swrite_8 (fp, race_outer);
WriteIpGroup (fp, &ip);
+1 -1
View File
@@ -412,7 +412,7 @@ SaveSummary (const SUMMARY_DESC *SummPtr, void *fp)
write_8 (fp, SummPtr->NumDevices);
write_a8 (fp, SummPtr->ShipList, MAX_BUILT_SHIPS);
write_a8 (fp, SummPtr->DeviceList, MAX_EXCLUSIVE_DEVICES);
write_a8 (fp, SummPtr->SaveName, strlen(SummPtr->SaveName));
write_a8 (fp, (BYTE *) SummPtr->SaveName, strlen(SummPtr->SaveName));
}
/* Save the Star Description chunk. This is not to be confused with
+2 -2
View File
@@ -1504,8 +1504,8 @@ SetGlobalOptions (GLOBALOPTS *opts)
else
NewGfxFlags &= ~TFB_GFXFLAGS_FULLSCREEN;
res_PutBoolean ("config.scanlines", opts->scanlines);
res_PutBoolean ("config.fullscreen", opts->fullscreen);
res_PutBoolean ("config.scanlines", (BOOLEAN)opts->scanlines);
res_PutBoolean ("config.fullscreen", (BOOLEAN)opts->fullscreen);
if ((NewWidth != ScreenWidthActual) ||
@@ -201,7 +201,7 @@ PacketHandler_Fleet(NetConnection *conn, const Packet_Fleet *packet) {
// the ships it says it contains.
log_add(log_Warning, "Invalid fleet size. Specified size is %d, "
"actual size = %d",
numShips, (len - sizeof packet) / sizeof(packet->ships[0]));
numShips, (int) ((len - sizeof packet) / sizeof(packet->ships[0])));
errno = EBADMSG;
return -1;
}
@@ -578,7 +578,7 @@ PacketHandler_Checksum(NetConnection *conn, const Packet_Checksum *packet) {
log_add(log_Warning, "NETPLAY: [%d] <== Received checksum "
"for frame %u, while we only expect checksums on frames "
"divisable by %u -- discarding.", conn->player,
(unsigned int) frameNr, interval);
(unsigned int) frameNr, (unsigned int) interval);
return 0;
// No need to close the connection; checksums are not
// essential.
@@ -593,7 +593,7 @@ PacketHandler_Checksum(NetConnection *conn, const Packet_Checksum *packet) {
log_add(log_Warning, "NETPLAY: [%d] <== Received checksum "
"for a frame too far in the future (frame %u, current "
"is %u, input delay is %u) -- discarding.", conn->player,
(unsigned int) frameNr, battleFrameCount, delay);
(unsigned int) frameNr, (unsigned int) battleFrameCount, (unsigned int) delay);
return 0;
// No need to close the connection; checksums are not
// essential.
@@ -610,7 +610,7 @@ PacketHandler_Checksum(NetConnection *conn, const Packet_Checksum *packet) {
log_add(log_Warning, "NETPLAY: [%d] <== Received checksum "
"for a frame too far in the past (frame %u, current "
"is %u, input delay is %u) -- discarding.", conn->player,
(unsigned int) frameNr, battleFrameCount, delay);
(unsigned int) frameNr, (unsigned int) battleFrameCount, (unsigned int) delay);
return 0;
// No need to close the connection; checksums are not
// essential.