pedantic: resolve flexible array member in nested struct

ISO C forbids a structure that has a flexible array member
to be a member of another structure or element of an
array.

filetx_pak and fileack_pak are two such structures. These
have been removed from doomdata_t's union.
This commit is contained in:
James R 2022-02-20 02:51:17 -08:00
parent bea79dfa65
commit 59c04ae041
3 changed files with 16 additions and 13 deletions

View file

@ -357,8 +357,8 @@ typedef struct
servertics_pak serverpak; // 132495 bytes (more around 360, no?)
serverconfig_pak servercfg; // 773 bytes
UINT8 textcmd[MAXTEXTCMD+1]; // 66049 bytes (wut??? 64k??? More like 257 bytes...)
filetx_pak filetxpak; // 139 bytes
fileack_pak fileack;
char filetxpak[sizeof (filetx_pak)];// 139 bytes
char fileack[sizeof (fileack_pak)];
UINT8 filereceived;
clientconfig_pak clientcfg; // 136 bytes
UINT8 md5sum[16];

View file

@ -913,11 +913,13 @@ static void DebugPrintpacket(const char *header)
case PT_SERVERREFUSE:
fprintf(debugfile, " reason %s\n", netbuffer->u.serverrefuse.reason);
break;
case PT_FILEFRAGMENT:
case PT_FILEFRAGMENT: {
filetx_pak *pak = (void*)&netbuffer->u.filetxpak;
fprintf(debugfile, " fileid %d datasize %d position %u\n",
netbuffer->u.filetxpak.fileid, (UINT16)SHORT(netbuffer->u.filetxpak.size),
(UINT32)LONG(netbuffer->u.filetxpak.position));
pak->fileid, (UINT16)SHORT(pak->size),
(UINT32)LONG(pak->position));
break;
}
case PT_REQUESTFILE:
default: // write as a raw packet
fprintfstringnewline((char *)netbuffer->u.textcmd,

View file

@ -1124,7 +1124,7 @@ void FileSendTicker(void)
}
// Build a packet containing a file fragment
p = &netbuffer->u.filetxpak;
p = (void*)&netbuffer->u.filetxpak;
fragmentsize = FILEFRAGMENTSIZE;
if (f->size-transfer[i].position < fragmentsize)
fragmentsize = f->size-transfer[i].position;
@ -1166,7 +1166,7 @@ void FileSendTicker(void)
void PT_FileAck(void)
{
fileack_pak *packet = &netbuffer->u.fileack;
fileack_pak *packet = (void*)&netbuffer->u.fileack;
INT32 node = doomcom->remotenode;
filetran_t *trans = &transfer[node];
INT32 i, j;
@ -1310,10 +1310,11 @@ void FileReceiveTicker(void)
void PT_FileFragment(void)
{
INT32 filenum = netbuffer->u.filetxpak.fileid;
filetx_pak *pak = (void*)&netbuffer->u.filetxpak;
INT32 filenum = pak->fileid;
fileneeded_t *file = &fileneeded[filenum];
UINT32 fragmentpos = LONG(netbuffer->u.filetxpak.position);
UINT16 fragmentsize = SHORT(netbuffer->u.filetxpak.size);
UINT32 fragmentpos = LONG(pak->position);
UINT16 fragmentsize = SHORT(pak->size);
UINT16 boundedfragmentsize = doomcom->datalength - BASEPACKETSIZE - sizeof(netbuffer->u.filetxpak);
char *filename;
@ -1381,7 +1382,7 @@ void PT_FileFragment(void)
CONS_Printf("\r%s...\n",filename);
file->currentsize = 0;
file->totalsize = LONG(netbuffer->u.filetxpak.filesize);
file->totalsize = LONG(pak->filesize);
file->ackresendposition = UINT32_MAX; // Only used for resumed downloads
file->receivedfragments = calloc(file->totalsize / fragmentsize + 1, sizeof(*file->receivedfragments));
@ -1397,7 +1398,7 @@ void PT_FileFragment(void)
if (fragmentpos >= file->totalsize)
I_Error("Invalid file fragment\n");
file->iteration = max(file->iteration, netbuffer->u.filetxpak.iteration);
file->iteration = max(file->iteration, pak->iteration);
if (!file->receivedfragments[fragmentpos / fragmentsize]) // Not received yet
{
@ -1405,7 +1406,7 @@ void PT_FileFragment(void)
// We can receive packets in the wrong order, anyway all OSes support gaped files
fseek(file->file, fragmentpos, SEEK_SET);
if (fragmentsize && fwrite(netbuffer->u.filetxpak.data, boundedfragmentsize, 1, file->file) != 1)
if (fragmentsize && fwrite(pak->data, boundedfragmentsize, 1, file->file) != 1)
I_Error("Can't write to %s: %s\n",filename, M_FileError(file->file));
file->currentsize += boundedfragmentsize;