Skip to content

Commit

Permalink
Merge pull request #598 from pbdot/fix-warnings
Browse files Browse the repository at this point in the history
Fix warnings under GCC
  • Loading branch information
pbdot authored Nov 4, 2023
2 parents 30cd663 + a039cb4 commit 7dc98b1
Show file tree
Hide file tree
Showing 44 changed files with 189 additions and 183 deletions.
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ if (MSVC)
# Unreferenced formal parameter, and there are many of these
add_definitions("/wd4100")

# warning level for edge specific source files
set (EDGE_WARNINGS "/W4")

# To use the sanitizer with MSVC, you will need to either have your Visual Studio
# or Build Tools install in your PATH variable, or copy the appropriate DLL to the program
# folder before launching. The paths and filenames can vary based on your setup,
Expand All @@ -64,11 +67,16 @@ if (MSVC)

set(CMAKE_EXE_LINKER_FLAGS "/SUBSYSTEM:WINDOWS")
else()

if (WIN32_CLANG)
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -Wall")

# warning level for edge specific source files
set (EDGE_WARNINGS -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-stringop-truncation -Wno-stringop-overflow)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")

if (EDGE_SANITIZE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
Expand Down
4 changes: 2 additions & 2 deletions source_files/ajbsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ target_include_directories(edge_ajbsp PRIVATE ../epi)
target_include_directories(edge_ajbsp PRIVATE ../miniz)

target_compile_options(edge_ajbsp PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:${EDGE_WARNINGS}>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${EDGE_WARNINGS}>
)
5 changes: 2 additions & 3 deletions source_files/ajbsp/bsp_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -868,16 +868,15 @@ void ParseLinedefField(linedef_t *line, const std::string& key, const std::strin
void ParseUDMF_Block(epi::lexer_c& lex, int cur_type)
{
vertex_t * vertex = NULL;
thing_t * thing = NULL;
sector_t * sector = NULL;
thing_t * thing = NULL;
sidedef_t * side = NULL;
linedef_t * line = NULL;

switch (cur_type)
{
case UDMF_VERTEX: vertex = NewVertex(); break;
case UDMF_THING: thing = NewThing(); break;
case UDMF_SECTOR: sector = NewSector(); break;
case UDMF_SECTOR: NewSector(); break;
case UDMF_SIDEDEF: side = NewSidedef(); break;
case UDMF_LINEDEF: line = NewLinedef(); break;
default: break;
Expand Down
2 changes: 1 addition & 1 deletion source_files/ajbsp/bsp_wad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ bool Lump_c::GetLine(char *buffer, size_t buf_size)
if (parent->mem_fp)
{
mem_pos = parent->mem_fp->Read(dest, 1);
*dest++;
dest++;
}
else
*dest++ = fgetc(parent->fp);
Expand Down
4 changes: 2 additions & 2 deletions source_files/coal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ add_library(
target_include_directories(edge_coal PRIVATE ../almostequals)

target_compile_options(edge_coal PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:${EDGE_WARNINGS}>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${EDGE_WARNINGS}>
)
15 changes: 10 additions & 5 deletions source_files/coal/c_compile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1497,14 +1497,13 @@ int real_vm_c::GLOB_FunctionBody(def_t *func_def, type_t *type, const char *func
//
// create the parmeters as locals
//
def_t *defs[MAX_PARMS];

for (int i=0 ; i < type->parm_num ; i++)
{
if (FindDef(type->parm_types[i], comp.parm_names[i], comp.scope))
CompileError("parameter %s redeclared\n", comp.parm_names[i]);

defs[i] = DeclareDef(type->parm_types[i], comp.parm_names[i], comp.scope);
DeclareDef(type->parm_types[i], comp.parm_names[i], comp.scope);
}

int code = EmitCode(OP_NULL);
Expand Down Expand Up @@ -1906,7 +1905,11 @@ real_vm_c::real_vm_c() :
{
// string #0 must be the empty string
int ofs = string_mem.alloc(2);
assert(ofs == 0);
if (ofs != 0)
{
RunError("string #0 must be the empty string\n");
}

strcpy((char *)string_mem.deref(0), "");


Expand All @@ -1919,8 +1922,10 @@ real_vm_c::real_vm_c() :

// statement #0 is never used
ofs = EmitCode(OP_RET);
assert(ofs == 0);

if (ofs != 0)
{
RunError("statement #0 is never used\n");
}

// global #0 is never used (equivalent to NULL)
// global #1-#3 are reserved for function return values
Expand Down
4 changes: 2 additions & 2 deletions source_files/ddf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ target_include_directories(edge_ddf PRIVATE ../edge)
target_include_directories(edge_ddf PRIVATE ../epi)

target_compile_options(edge_ddf PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:${EDGE_WARNINGS}>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${EDGE_WARNINGS}>
)
4 changes: 4 additions & 0 deletions source_files/ddf/language.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ std::string DDF_SanitizeName(const std::string& s)
// Until unicode is truly implemented, restrict characters to extended ASCII
std::string DDF_SanitizePrintString(const std::string& s)
{
return std::string(s);
// This is always true and warns as std::string is char
/*
std::string out;
for (size_t i = 0 ; i < s.size() ; i++)
Expand All @@ -76,6 +79,7 @@ std::string DDF_SanitizePrintString(const std::string& s)
}
return out;
*/
}

class lang_choice_c
Expand Down
4 changes: 2 additions & 2 deletions source_files/ddf/thing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ static bool BenefitTryCounterLimit(const char *name, benefit_t *be,
int num_vals)
{
char namebuf[200];
int len = strlen(name);
size_t len = strlen(name);

// check for ".LIMIT" prefix
if (len < 7 || DDF_CompareName(name+len-6, ".LIMIT") != 0)
Expand Down Expand Up @@ -1225,7 +1225,7 @@ static bool BenefitTryAmmoLimit(const char *name, benefit_t *be,
int num_vals)
{
char namebuf[200];
int len = strlen(name);
size_t len = strlen(name);

// check for ".LIMIT" prefix

Expand Down
4 changes: 2 additions & 2 deletions source_files/dehacked/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ target_include_directories(edge_deh PRIVATE ../epi)
target_include_directories(edge_deh PRIVATE ../ddf)

target_compile_options(edge_deh PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:${EDGE_WARNINGS}>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${EDGE_WARNINGS}>
)
4 changes: 2 additions & 2 deletions source_files/ec_voxelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ add_library(
target_include_directories(ec_voxelib PRIVATE ../almostequals)

target_compile_options(ec_voxelib PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:${EDGE_WARNINGS}>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${EDGE_WARNINGS}>
)
27 changes: 9 additions & 18 deletions source_files/ec_voxelib/ec_voxelib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1885,16 +1885,6 @@ void VoxelMesh::createFrom (VoxelData &vox, int optlevel) {
// GLVoxelMesh
// ////////////////////////////////////////////////////////////////////////// //

//==========================================================================
//
// normNegZero
//
//==========================================================================
static inline void normNegZero (float *f) {
if (*f == 0.0f) memset((void *)f, 0, sizeof(*f));
}


//==========================================================================
//
// GLVoxelMesh::appendVertex
Expand All @@ -1903,14 +1893,15 @@ static inline void normNegZero (float *f) {
uint32_t GLVoxelMesh::appendVertex (VVoxVertexEx &gv) {
++totaladded;
// normalize negative zeroes
normNegZero(&gv.x);
normNegZero(&gv.y);
normNegZero(&gv.z);
normNegZero(&gv.s);
normNegZero(&gv.t);
normNegZero(&gv.nx);
normNegZero(&gv.ny);
normNegZero(&gv.nz);
if (AlmostEquals(gv.x, 0.0f)) gv.x = 0.0f;
if (AlmostEquals(gv.y, 0.0f)) gv.y = 0.0f;
if (AlmostEquals(gv.z, 0.0f)) gv.z = 0.0f;
if (AlmostEquals(gv.s, 0.0f)) gv.s = 0.0f;
if (AlmostEquals(gv.t, 0.0f)) gv.t = 0.0f;
if (AlmostEquals(gv.nx, 0.0f)) gv.nx = 0.0f;
if (AlmostEquals(gv.ny, 0.0f)) gv.ny = 0.0f;
if (AlmostEquals(gv.nz, 0.0f)) gv.nz = 0.0f;

// check hashtable
auto vp = vertcache.get(gv);
if (vp) return *vp;
Expand Down
22 changes: 11 additions & 11 deletions source_files/edge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,30 @@ else()
set(EDGE_LINK_LIBRARIES ${EDGE_LINK_LIBRARIES} gl4es)
endif()

target_include_directories(edge-classic PRIVATE ../almostequals)
target_include_directories(edge-classic SYSTEM PRIVATE ../almostequals)
target_include_directories(edge-classic PRIVATE ../ajbsp)
target_include_directories(edge-classic PRIVATE ../coal)
target_include_directories(edge-classic PRIVATE ../crsid)
target_include_directories(edge-classic SYSTEM PRIVATE ../crsid)
target_include_directories(edge-classic PRIVATE ../ddf)
target_include_directories(edge-classic PRIVATE ../dehacked)
target_include_directories(edge-classic PRIVATE ../dr_libs)
target_include_directories(edge-classic SYSTEM PRIVATE ../dr_libs)
target_include_directories(edge-classic PRIVATE ../ec_voxelib)
target_include_directories(edge-classic PRIVATE ../epi)
target_include_directories(edge-classic PRIVATE ../libprimesynth)
target_include_directories(edge-classic PRIVATE ../libRAD)
target_include_directories(edge-classic PRIVATE ../m4p)
target_include_directories(edge-classic PRIVATE ../minivorbis)
target_include_directories(edge-classic PRIVATE ../miniz)
target_include_directories(edge-classic PRIVATE ../stb)
target_include_directories(edge-classic SYSTEM PRIVATE ../libprimesynth)
target_include_directories(edge-classic SYSTEM PRIVATE ../libRAD)
target_include_directories(edge-classic SYSTEM PRIVATE ../m4p)
target_include_directories(edge-classic SYSTEM PRIVATE ../minivorbis)
target_include_directories(edge-classic SYSTEM PRIVATE ../miniz)
target_include_directories(edge-classic SYSTEM PRIVATE ../stb)
if(MSVC OR WIN32_CLANG)
target_include_directories(edge-classic PRIVATE ../sdl2/include)
endif()

target_link_libraries(edge-classic PRIVATE ${EDGE_LINK_LIBRARIES})

target_compile_options(edge-classic PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:${EDGE_WARNINGS}>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${EDGE_WARNINGS}>
)

set(COPY_FILES "")
Expand Down
3 changes: 2 additions & 1 deletion source_files/edge/am_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ static void DrawMLineDoor(mline_t * ml, rgbcol_t rgb)
HUD_SolidLine(x1, y1, x2, y2, rgb, linewidth, true, dx, dy);
}

/*
static mline_t door_key[] =
{
{{-2, 0}, {-1.7, -0.5}},
Expand All @@ -622,7 +623,7 @@ static mline_t door_key[] =
};
#define NUMDOORKEYLINES (sizeof(door_key)/sizeof(mline_t))

*/

static mline_t player_dagger[] =
{
Expand Down
2 changes: 0 additions & 2 deletions source_files/edge/bot_nav.cc
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,6 @@ static void NAV_EnemiesInSubsector(const subsector_t *sub, bot_t *bot, float rad

static void NAV_EnemiesInNode(unsigned int bspnum, bot_t *bot, float radius, mobj_t*& best_mo, float& best_score)
{
SYS_ASSERT(bspnum >= 0);

if (bspnum & NF_V5_SUBSECTOR)
{
bspnum &= ~NF_V5_SUBSECTOR;
Expand Down
2 changes: 1 addition & 1 deletion source_files/edge/con_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static cvar_c * all_cvars = NULL;
cvar_c::cvar_c(const char *_name, const char *_def, int _flags, float _min, float _max, cvar_callback _cb) :
d(), f(), s(_def),
name(_name), def(_def), flags(_flags), min(_min), max(_max),
modified(0), cvar_cb(_cb)
cvar_cb(_cb), modified(0)
{
ParseString();

Expand Down
18 changes: 9 additions & 9 deletions source_files/edge/e_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static void SetGlobalVars(void)
}

p = argv::Find("res");
if (p > 0 && p + 2 < argv::list.size() && !argv::IsOption(p+1) && !argv::IsOption(p+2))
if (p > 0 && p + 2 < int(argv::list.size()) && !argv::IsOption(p+1) && !argv::IsOption(p+2))
{
if (DISPLAYMODE == 2)
I_Warning("Current display mode set to borderless fullscreen. Provided resolution of %dx%d will be ignored!\n",
Expand Down Expand Up @@ -356,7 +356,7 @@ static void SetGlobalVars(void)
p = argv::Find("spritekludge");
if (p > 0)
{
if (p + 1 < argv::list.size() && !argv::IsOption(p+1))
if (p + 1 < int(argv::list.size()) && !argv::IsOption(p+1))
sprite_kludge = atoi(argv::list[p+1].c_str());

if (!sprite_kludge)
Expand Down Expand Up @@ -1343,7 +1343,7 @@ static void CheckTurbo(void)

if (p > 0)
{
if (p + 1 < argv::list.size() && !argv::IsOption(p+1))
if (p + 1 < int(argv::list.size()) && !argv::IsOption(p+1))
turbo_scale = atoi(argv::list[p+1].c_str());
else
turbo_scale = 200;
Expand Down Expand Up @@ -1453,7 +1453,7 @@ static void AddCommandLineFiles(void)

int p;

for (p = 1; p < argv::list.size() && !argv::IsOption(p); p++)
for (p = 1; p < int(argv::list.size()) && !argv::IsOption(p); p++)
{
AddSingleCmdLineFile(std::filesystem::u8path(argv::list[p]), false);
}
Expand All @@ -1462,7 +1462,7 @@ static void AddCommandLineFiles(void)

p = argv::Find("file");

while (p > 0 && p < argv::list.size() && (!argv::IsOption(p) || epi::strcmp(argv::list[p], "-file") == 0))
while (p > 0 && p < int(argv::list.size()) && (!argv::IsOption(p) || epi::strcmp(argv::list[p], "-file") == 0))
{
// the parms after p are wadfile/lump names,
// go until end of parms or another '-' preceded parm
Expand All @@ -1476,7 +1476,7 @@ static void AddCommandLineFiles(void)

p = argv::Find("script");

while (p > 0 && p < argv::list.size() && (!argv::IsOption(p) || epi::strcmp(argv::list[p], "-script") == 0))
while (p > 0 && p < int(argv::list.size()) && (!argv::IsOption(p) || epi::strcmp(argv::list[p], "-script") == 0))
{
// the parms after p are script filenames,
// go until end of parms or another '-' preceded parm
Expand Down Expand Up @@ -1507,7 +1507,7 @@ static void AddCommandLineFiles(void)

p = argv::Find("deh");

while (p > 0 && p < argv::list.size() && (!argv::IsOption(p) || epi::strcmp(argv::list[p], "-deh") == 0))
while (p > 0 && p < int(argv::list.size()) && (!argv::IsOption(p) || epi::strcmp(argv::list[p], "-deh") == 0))
{
// the parms after p are Dehacked/BEX filenames,
// go until end of parms or another '-' preceded parm
Expand Down Expand Up @@ -1537,7 +1537,7 @@ static void AddCommandLineFiles(void)

p = argv::Find("dir");

while (p > 0 && p < argv::list.size() && (!argv::IsOption(p) || epi::strcmp(argv::list[p],"-dir") == 0))
while (p > 0 && p < int(argv::list.size()) && (!argv::IsOption(p) || epi::strcmp(argv::list[p],"-dir") == 0))
{
// the parms after p are directory names,
// go until end of parms or another '-' preceded parm
Expand Down Expand Up @@ -1808,7 +1808,7 @@ static void E_InitialState(void)
{
warp_deathmatch = 1;

if (pp + 1 < argv::list.size() && !argv::IsOption(pp+1))
if (pp + 1 < int(argv::list.size()) && !argv::IsOption(pp+1))
warp_deathmatch = MAX(1, atoi(argv::list[pp+1].c_str()));

warp = true;
Expand Down
2 changes: 1 addition & 1 deletion source_files/edge/f_finale.cc
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ void F_Drawer(void)

case f_pic:
{
const image_c *image = W_ImageLookup(finale->pics[MIN(picnum, finale->pics.size()-1)].c_str());
const image_c *image = W_ImageLookup(finale->pics[MIN((size_t)picnum, finale->pics.size()-1)].c_str());
if (r_titlescaling.d == 2) // Stretch
HUD_StretchImage(hud_x_left, 0, hud_x_right-hud_x_left, 200, image, 0, 0);
else
Expand Down
2 changes: 1 addition & 1 deletion source_files/edge/i_video.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void I_StartupGraphics(void)
// If needed, set the default window toggle mode to the largest non-native res
if (tw_displaymode.d == scrmode_c::SCR_INVALID)
{
for (int i = 0; i < screen_modes.size(); i++)
for (size_t i = 0; i < screen_modes.size(); i++)
{
scrmode_c *check = screen_modes[i];
if (check->display_mode == scrmode_c::SCR_WINDOW)
Expand Down
Loading

0 comments on commit 7dc98b1

Please sign in to comment.