Skip to content

Commit

Permalink
fix all cppcheck and -Wall compiler warnings (#19)
Browse files Browse the repository at this point in the history
* fix all compiler warnings, pt 1

* fix all compiler warnings, pt 2

* fix all compiler warnings, pt 3

* fix all cppcheck warnings

* fix all compiler warnings, pt 4

* add Travis CI

* git update-index --chmod=+x ./.travis.sh

* switch Travis CI template to C++

* fix ignoring return value of read()

* fix ignoring return value of read(), pt 2

* fix ignoring return value of fread(), pt 1

* fix output between x and y bytes into a destination of size z

* remove license-mame.txt, we are not using code under this license anymore

* organize all available statetype variables in a states[] array (#17)

* organize all available statetype variables in a states[] array

This replaces the current relying on a specific order in which global variables
are stored in the executable for e.g. saving and restoring of savegames and thus
does not require the -fno-toplevel-reorder compiler flag anymore.

Fixes #15.

* add the files containing the states[] array

* simplify pointer arithmetics in SaveTheGame()/LoadTheGame()

* display a message and quit the game when an invalid savegame is loaded

There is currently no other way to "unload" the savegame.

* back to main menu on failure instead of quitting

* add copyright headers to newly added files

* prevent crashes for subsequent games when loading invalid savegame

* add some minimalistic comments

* fix all compiler warnings, pt 1

* fix all compiler warnings, pt 2

* fix all compiler warnings, pt 3

* fix all cppcheck warnings

* fix all compiler warnings, pt 4

* add Travis CI

* git update-index --chmod=+x ./.travis.sh

* switch Travis CI template to C++

* fix ignoring return value of read()

* fix ignoring return value of read(), pt 2

* fix ignoring return value of fread(), pt 1

* fix output between x and y bytes into a destination of size z

* unbreak rebase breakage

* fix some more "ignoring return value of read()/write()/fread()" warnings

* fix "ignoring return value of read()" in wl_menu.cpp

* fix some misc errors

* fix SOD compilation

* fix "the current #pragma pack aligment value is modified" warning with clang++

* let Travis CI build 6 separate binaries

* include wl_def.h in dosbox/dbopl.cpp instead of setting "#pragma pack()" there
  • Loading branch information
fabiangreffrath authored Jul 14, 2020
1 parent f7e2b2c commit 78cc9d6
Show file tree
Hide file tree
Showing 24 changed files with 411 additions and 212 deletions.
56 changes: 56 additions & 0 deletions .travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
if [ "$ANALYZE" = "true" ] ; then
cppcheck -DO_BINARY=0 -DDEBUGKEYS -DARTSEXTERN -DDEMOSEXTERN -DPLAYDEMOLIKEORIGINAL \
-UUSE_FEATUREFLAGS -UUSE_SHADING -UUSE_DIR3DSPR -UUSE_FLOORCEILINGTEX -UUSE_HIRES \
-UUSE_PARALLAX -UUSE_CLOUDSKY -UUSE_STARSKY -UUSE_RAIN -UUSE_SNOW -UFIXRAINSNOWLEAKS \
-UGP2X -UGP2X_940 -U_arch_dreamcast -USPANISH -UNOTYET \
--error-exitcode=1 --force -Idosbox . 2> stderr.txt
RET=$?
if [ -s stderr.txt ]
then
cat stderr.txt
fi
exit $RET
else
set -e

export Q=""
export CFLAGS="-Werror"

echo "Wolf3d Full v1.4 GT/ID/Activision"
make BINARY=wolf4sdl-wl6
make clean

echo "Wolf3d Full v1.4 Apogee (with ReadThis)"
sed -e "s|^\(//\)\?\(#define GOODTIMES\)|//\2|" -i version.h
make BINARY=wolf4sdl-wl6a
make clean

echo "Wolf3d Full v1.1 Apogee (with ReadThis)"
sed -e "s|^\(//\)\?\(#define APOGEE_1_1\)|\2|" -i version.h
make BINARY=wolf4sdl-wl6a1
make clean

echo "Wolf3d Shareware v1.4"
sed -e "s|^\(//\)\?\(#define APOGEE_1_1\)|//\2|" -i version.h
sed -e "s|^\(//\)\?\(#define UPLOAD\)|\2|" -i version.h
make BINARY=wolf4sdl-wl1
make clean

echo "Spear of Destiny Full and Mission Disks (and GOODTIMES for no FormGen quiz)"
sed -e "s|^\(//\)\?\(#define UPLOAD\)|//\2|" -i version.h
sed -e "s|^\(//\)\?\(#define SPEAR\)|\2|" -i version.h
sed -e "s|^\(//\)\?\(#define GOODTIMES\)|\2|" -i version.h
make BINARY=wolf4sdl-sod
make clean

echo "Spear of Destiny Demo"
sed -e "s|^\(//\)\?\(#define GOODTIMES\)|//\2|" -i version.h
sed -e "s|^\(//\)\?\(#define SPEARDEMO\)|\2|" -i version.h
make BINARY=wolf4sdl-sdm
make clean

sed -e "s|^\(//\)\?\(#define SPEAR\)|//\2|" -i version.h
sed -e "s|^\(//\)\?\(#define SPEARDEMO\)|//\2|" -i version.h
sed -e "s|^\(//\)\?\(#define GOODTIMES\)|\2|" -i version.h
fi
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: cpp

cache: ccache

compiler:
- gcc
- clang

sudo: required
dist: bionic

matrix:
include:
- compiler: gcc
env: ANALYZE=true

addons:
apt:
packages:
- cppcheck
- libsdl2-dev
- libsdl2-mixer-dev

script: ./.travis.sh

branches:
only:
- master
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LDFLAGS_SDL ?= $(shell $(SDL_CONFIG) --libs)

CFLAGS += $(CFLAGS_SDL)

#CFLAGS += -Wall
CFLAGS += -Wall
#CFLAGS += -W
CFLAGS += -Wpointer-arith
CFLAGS += -Wreturn-type
Expand Down
7 changes: 5 additions & 2 deletions dosbox/dbopl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@
#include <stdlib.h>
#include <string.h>

#pragma pack(1)
#include "../wl_def.h"

//#include "dosbox.h"
#include "dbopl.h"


#ifndef PI
#define PI 3.14159265358979323846
#endif
Expand Down Expand Up @@ -891,6 +890,8 @@ Channel* Channel::BlockTemplate( Chip* chip, Bit32u samples, Bit32s* output ) {
return (this + 2);
}
break;
default:
break;
}
//Init the operators with the the current vibrato and tremolo values
Op( 0 )->Prepare( chip );
Expand Down Expand Up @@ -956,6 +957,8 @@ Channel* Channel::BlockTemplate( Chip* chip, Bit32u samples, Bit32s* output ) {
output[ i * 2 + 0 ] += sample & maskLeft;
output[ i * 2 + 1 ] += sample & maskRight;
break;
default:
break;
}
}
switch( mode ) {
Expand Down
93 changes: 74 additions & 19 deletions id_ca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ loaded into the data segment
#endif

#include "wl_def.h"
#pragma hdrstop

#define THREEBYTEGRSTARTS

Expand Down Expand Up @@ -139,7 +138,10 @@ static int32_t GRFILEPOS(const size_t idx)
void CAL_GetGrChunkLength (int chunk)
{
lseek(grhandle,GRFILEPOS(chunk),SEEK_SET);
read(grhandle,&chunkexplen,sizeof(chunkexplen));
if (read(grhandle,&chunkexplen,sizeof(chunkexplen)) < 0)
{
return;
}
chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4;
}

Expand Down Expand Up @@ -467,7 +469,11 @@ void CAL_SetupGrFile (void)
if (handle == -1)
CA_CannotOpen(fname);

read(handle, grhuffman, sizeof(grhuffman));
if (read(handle, grhuffman, sizeof(grhuffman)) < 0)
{
close(handle);
return;
}
close(handle);

// load the data offsets from ???head.ext
Expand Down Expand Up @@ -495,7 +501,11 @@ void CAL_SetupGrFile (void)
fname, headersize / 3, expectedsize);

byte data[lengthof(grstarts) * 3];
read(handle, data, sizeof(data));
if (read(handle, data, sizeof(data)) < 0)
{
close(handle);
return;
}
close(handle);

const byte* d = data;
Expand Down Expand Up @@ -526,7 +536,11 @@ void CAL_SetupGrFile (void)
CAL_GetGrChunkLength(STRUCTPIC); // position file pointer
compseg=(byte *) malloc(chunkcomplen);
CHECKMALLOCRESULT(compseg);
read (grhandle,compseg,chunkcomplen);
if (read (grhandle,compseg,chunkcomplen) < 0)
{
free(compseg);
return;
}
CAL_HuffExpand(compseg, (byte*)pictable, NUMPICS * sizeof(pictabletype), grhuffman);
free(compseg);
}
Expand Down Expand Up @@ -562,7 +576,12 @@ void CAL_SetupMapFile (void)
length = NUMMAPS*4+2; // used to be "filelength(handle);"
mapfiletype *tinf=(mapfiletype *) malloc(sizeof(mapfiletype));
CHECKMALLOCRESULT(tinf);
read(handle, tinf, length);
if (read(handle, tinf, length) < 0)
{
close(handle);
free(tinf);
return;
}
close(handle);

RLEWtag=tinf->RLEWtag;
Expand Down Expand Up @@ -598,7 +617,11 @@ void CAL_SetupMapFile (void)
mapheaderseg[i]=(maptype *) malloc(sizeof(maptype));
CHECKMALLOCRESULT(mapheaderseg[i]);
lseek(maphandle,pos,SEEK_SET);
read (maphandle,(memptr)mapheaderseg[i],sizeof(maptype));
if (read (maphandle,(memptr)mapheaderseg[i],sizeof(maptype)) < 0)
{
free(tinf);
return;
}
}

free(tinf);
Expand Down Expand Up @@ -693,7 +716,7 @@ void CA_Startup (void)

void CA_Shutdown (void)
{
int i,start;
int i,start = STARTPCSOUNDS;

if(maphandle != -1)
close(maphandle);
Expand Down Expand Up @@ -744,7 +767,12 @@ int32_t CA_CacheAudioChunk (int chunk)
CHECKMALLOCRESULT(audiosegs[chunk]);

lseek(audiohandle,pos,SEEK_SET);
read(audiohandle,audiosegs[chunk],size);
if (read(audiohandle,audiosegs[chunk],size) < 0)
{
free(audiosegs[chunk]);
audiosegs[chunk] = NULL;
return 0;
}

return size;
}
Expand All @@ -758,10 +786,14 @@ void CA_CacheAdlibSoundChunk (int chunk)
return; // already in memory

lseek(audiohandle, pos, SEEK_SET);
read(audiohandle, bufferseg, ORIG_ADLIBSOUND_SIZE - 1); // without data[1]
if (read(audiohandle, bufferseg, ORIG_ADLIBSOUND_SIZE - 1) < 0) // without data[1]
{
return;
}

AdLibSound *sound = (AdLibSound *) malloc(size + sizeof(AdLibSound) - ORIG_ADLIBSOUND_SIZE);
CHECKMALLOCRESULT(sound);
audiosegs[chunk] = (byte *) malloc(size + sizeof(AdLibSound) - ORIG_ADLIBSOUND_SIZE);
CHECKMALLOCRESULT(audiosegs[chunk]);
AdLibSound *sound = (AdLibSound *) audiosegs[chunk];

byte *ptr = (byte *) bufferseg;
sound->common.length = READLONGWORD(ptr);
Expand All @@ -784,7 +816,12 @@ void CA_CacheAdlibSoundChunk (int chunk)
sound->inst.unused[2] = *ptr++;
sound->block = *ptr++;

read(audiohandle, sound->data, size - ORIG_ADLIBSOUND_SIZE + 1); // + 1 because of byte data[1]
if (read(audiohandle, sound->data, size - ORIG_ADLIBSOUND_SIZE + 1) < 0) // + 1 because of byte data[1]
{
free(audiosegs[chunk]);
audiosegs[chunk] = NULL;
return;
}

audiosegs[chunk]=(byte *) sound;
}
Expand All @@ -803,7 +840,7 @@ void CA_CacheAdlibSoundChunk (int chunk)

void CA_LoadAllSounds (void)
{
unsigned start,i;
unsigned start = STARTPCSOUNDS,i;

switch (oldsoundmode)
{
Expand Down Expand Up @@ -943,14 +980,21 @@ void CA_CacheGrChunk (int chunk)

if (compressed<=BUFFERSIZE)
{
read(grhandle,bufferseg,compressed);
if (read(grhandle,bufferseg,compressed) < 0)
{
return;
}
source = bufferseg;
}
else
{
source = (int32_t *) malloc(compressed);
CHECKMALLOCRESULT(source);
read(grhandle,source,compressed);
if (read(grhandle,source,compressed) < 0)
{
free(source);
return;
}
}

CAL_ExpandGrChunk (chunk,source);
Expand Down Expand Up @@ -996,7 +1040,11 @@ void CA_CacheScreen (int chunk)

bigbufferseg=malloc(compressed);
CHECKMALLOCRESULT(bigbufferseg);
read(grhandle,bigbufferseg,compressed);
if (read(grhandle,bigbufferseg,compressed) < 0)
{
free(bigbufferseg);
return;
}
source = (int32_t *) bigbufferseg;

expanded = *source++;
Expand Down Expand Up @@ -1045,7 +1093,7 @@ void CA_CacheMap (int mapnum)
int32_t pos,compressed;
int plane;
word *dest;
memptr bigbufferseg;
memptr bigbufferseg = NULL;
unsigned size;
word *source;
#ifdef CARMACIZED
Expand Down Expand Up @@ -1077,7 +1125,14 @@ void CA_CacheMap (int mapnum)
source = (word *) bigbufferseg;
}

read(maphandle,source,compressed);
if (read(maphandle,source,compressed) < 0)
{
if (bigbufferseg)
{
free(bigbufferseg);
}
return;
}
#ifdef CARMACIZED
//
// unhuffman, then unRLEW
Expand Down
6 changes: 5 additions & 1 deletion id_in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void processEvent(SDL_Event *event)
}
}

int sym = LastScan;
unsigned int sym = LastScan;
if(sym >= 'a' && sym <= 'z')
sym -= 32; // convert to uppercase

Expand Down Expand Up @@ -445,7 +445,9 @@ IN_Shutdown(void)
return;

if(Joystick)
{
SDL_JoystickClose(Joystick);
}

IN_Started = false;
}
Expand Down Expand Up @@ -505,7 +507,9 @@ IN_ReadControl(int player,ControlInfo *info)
if (Keyboard[KbdDefs.button0])
buttons += 1 << 0;
if (Keyboard[KbdDefs.button1])
{
buttons += 1 << 1;
}

dx = mx * 127;
dy = my * 127;
Expand Down
Loading

0 comments on commit 78cc9d6

Please sign in to comment.