Skip to content
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

MSVC Warning cleanup, /WX (Werror), and misc. fixes #790

Merged
merged 12 commits into from
Nov 26, 2024
45 changes: 40 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,43 @@ set(CMAKE_C_STANDARD 11)
if(MSVC)
# remove cmake's default /W3 to avoid warning D9025
string(REGEX REPLACE "/W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# we would probably like to pass /Wall instead of /W4, but there's a lot
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /permissive- /W4")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /permissive- /W4 /WX")
# Disable select warnings:
# C4100: unreferenced formal parameter
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100")
# C4456: declaration hides previous local declaration
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4456")
# C4459: declaration hides previous global declaration
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4459")
# C4244: implicit conversion, possible loss of data
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244")
# C4267: implicit conversion from size_t, possible loss of data
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267")
# C4389: 'equality-operator' : signed/unsigned mismatch
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4389")
# _CRT_SECURE_NO_WARNINGS: disable warnings when calling functions like strncpy or sscanf
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
# _CRT_NONSTDC_NO_WARNINGS: disable warnings when calling POSIX functions like fileno
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D_CRT_NONSTDC_NO_WARNINGS")

# Error on certain warnings:
# C4013: call to undefined function
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4013")
# C4146: unary minus operator applied to unsigned type, result still unsigned
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4146")
# C4245: signed const to unsigned
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4245")
# C4305: truncation from double to float
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4305")
# C4701: potentially uninitialized local variable used
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4701")
# C4668: undefined symbol used as compiler directive (will evaluate to 0).
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4668")
# C4702: unreachable code
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4702")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wformat -pedantic -Wvla")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -DDEBUGMODE -Werror -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -Werror -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -g -O2 -fno-omit-frame-pointer -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -DNDEBUG")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Os -DNDEBUG")
Expand All @@ -62,8 +94,7 @@ add_definitions(-DV_MAJOR=${VERSION_MAJOR} -DV_MINOR=${VERSION_MINOR} -DV_PATCH=
# Enable AddressSanitizer if requested
if(USE_SANITIZERS)
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
add_compile_options("-fsanitize=address")
add_link_options("-fsanitize=address")
add_compile_options("/fsanitize=address")
message(STATUS "Development: Asan enabled. Ubsan is unsupported by MSVC.")
else()
add_compile_options("-fsanitize=address,undefined")
Expand Down Expand Up @@ -178,6 +209,7 @@ set_source_files_properties("src/video/video.c" PROPERTIES COMPILE_DEFINITIONS "
# Build core sources first as an object library
# this can then be reused in tests and main executable to speed things up
add_library(openomf_core OBJECT ${OPENOMF_SRC})
target_compile_definitions(openomf_core PUBLIC "$<$<CONFIG:Debug>:DEBUGMODE>")
omf_target_precompile_headers(openomf_core PUBLIC
"<SDL.h>"
"<enet/enet.h>"
Expand Down Expand Up @@ -246,6 +278,9 @@ include_directories(${COREINCS})

# Build the game binary
add_executable(openomf src/main.c src/engine.c ${ICON_RESOURCE})
set_property(TARGET openomf PROPERTY
VS_DEBUGGER_ENVIRONMENT "OPENOMF_SHADER_DIR=${CMAKE_CURRENT_BINARY_DIR}/shaders
OPENOMF_RESOURCE_DIR=${CMAKE_CURRENT_BINARY_DIR}/resources")
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT openomf)

# This is used to copy shader files from source directory to the binary output directory during compile.
Expand Down
36 changes: 18 additions & 18 deletions src/controller/ai_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->pref_jump = -10;
pilot->pref_fwd = 30;
pilot->pref_back = 10;
pilot->learning = 1.5;
pilot->forget = 0.25;
pilot->learning = 1.5f;
pilot->forget = 0.25f;
break;
case 1:
// steffan
Expand All @@ -813,8 +813,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->pref_jump = 6;
pilot->pref_fwd = 20;
pilot->pref_back = -9;
pilot->learning = 1.0;
pilot->forget = 0.4;
pilot->learning = 1.0f;
pilot->forget = 0.4f;
break;
case 2:
// milano
Expand All @@ -831,8 +831,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->pref_jump = 8;
pilot->pref_fwd = 30;
pilot->pref_back = -3;
pilot->learning = 0.9;
pilot->forget = 0.1;
pilot->learning = 0.9f;
pilot->forget = 0.1f;
break;
case 3:
// christian
Expand All @@ -848,8 +848,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->pref_jump = 2;
pilot->pref_fwd = 10;
pilot->pref_back = -10;
pilot->learning = 2.5;
pilot->forget = 0.35;
pilot->learning = 2.5f;
pilot->forget = 0.35f;
break;
case 4:
// shirro
Expand All @@ -867,8 +867,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->pref_jump = -20;
pilot->pref_fwd = 10;
pilot->pref_back = 10;
pilot->learning = 2.0;
pilot->forget = 0.2;
pilot->learning = 2.0f;
pilot->forget = 0.2f;
break;
case 5:
// jean-paul
Expand All @@ -884,8 +884,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->ap_low = 100;
pilot->ap_middle = -50;
pilot->pref_fwd = 20;
pilot->learning = 1.2;
pilot->forget = 0.07;
pilot->learning = 1.2f;
pilot->forget = 0.07f;
break;
case 6:
// ibrahim
Expand All @@ -902,8 +902,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->pref_jump = 2;
pilot->pref_fwd = 10;
pilot->pref_back = -10;
pilot->learning = 2.5;
pilot->forget = 0.05;
pilot->learning = 2.5f;
pilot->forget = 0.05f;
break;
case 7:
// angel
Expand All @@ -919,8 +919,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->pref_jump = 40;
pilot->pref_fwd = 40;
pilot->pref_back = -9;
pilot->learning = 3.0;
pilot->forget = 0.15;
pilot->learning = 3.0f;
pilot->forget = 0.15f;
break;
case 8:
// cossette
Expand All @@ -937,8 +937,8 @@ void reset_pilot_personality(sd_pilot *pilot) {
pilot->ap_middle = -50;
pilot->pref_jump = -10;
pilot->pref_back = 10;
pilot->learning = 0.7;
pilot->forget = 0.2;
pilot->learning = 0.7f;
pilot->forget = 0.2f;
break;
case 9:
// raven
Expand Down
8 changes: 4 additions & 4 deletions src/game/objects/har.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ void har_spawn_oil(object *obj, vec2i pos, int amount, float gravity, int layer)

// Make sure the oil drops have somekind of velocity
// (to prevent floating scrap objects)
if(vely < 0.1 && vely > -0.1)
vely += 0.21;
if(vely < 0.1f && vely > -0.1f)
vely += 0.21f;

// Create the object
object *scrap = omf_calloc(1, sizeof(object));
Expand Down Expand Up @@ -754,8 +754,8 @@ void har_spawn_scrap(object *obj, vec2i pos, int amount) {

// Make sure scrap has somekind of velocity
// (to prevent floating scrap objects)
if(vely < 0.1 && vely > -0.1)
vely += 0.21;
if(vely < 0.1f && vely > -0.1f)
vely += 0.21f;

// Create the object
object *scrap = omf_calloc(1, sizeof(object));
Expand Down
2 changes: 1 addition & 1 deletion src/game/objects/scrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void scrap_move(object *obj) {
vel.y += obj->gravity;
pos.y += vel.y;

float dampen = 0.4;
float dampen = 0.4f;

if(pos.x < ARENA_LEFT_WALL) {
pos.x = ARENA_LEFT_WALL;
Expand Down
4 changes: 2 additions & 2 deletions src/game/protos/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void player_clear_frame(object *obj) {

void player_create(object *obj) {
memset(&obj->animation_state, 0, sizeof(player_animation_state));
obj->animation_state.previous_tick = -1;
obj->animation_state.previous_tick = ~0u;
sd_script_create(&obj->animation_state.parser);
player_clear_frame(obj);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ void player_reload(object *obj) {
}

void player_reset(object *obj) {
obj->animation_state.previous_tick = -1;
obj->animation_state.previous_tick = ~0u;
obj->animation_state.current_tick = 0;
obj->animation_state.finished = 0;
obj->animation_state.previous = -1;
Expand Down
4 changes: 2 additions & 2 deletions src/game/scenes/arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,8 @@ void arena_dynamic_tick(scene *scene, int paused) {

// Make sure scrap has somekind of velocity
// (to prevent floating scrap objects)
if(vely < 0.1 && vely > -0.1)
vely += 0.21;
if(vely < 0.1f && vely > -0.1f)
vely += 0.21f;

// Create the object
object *scrap = omf_calloc(1, sizeof(object));
Expand Down
2 changes: 1 addition & 1 deletion src/game/scenes/scoreboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int scoreboard_create(scene *scene) {
}

// Darken the colors for the background a bit.
vga_state_mul_base_palette(0, 0xEF, 0.6);
vga_state_mul_base_palette(0, 0xEF, 0.6f);

if(local->has_pending_data) {
text_settings small_text;
Expand Down
6 changes: 4 additions & 2 deletions src/game/utils/nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ bool nat_create_upnp_mapping(nat_ctx *ctx, uint16_t int_port, uint16_t ext_port)
// like overly short lifetimes
return false;
}
#endif
#else
return false;
#endif
}

bool nat_create_pmp_mapping(nat_ctx *ctx, uint16_t int_port, uint16_t ext_port) {
Expand Down Expand Up @@ -70,8 +71,9 @@ bool nat_create_pmp_mapping(nat_ctx *ctx, uint16_t int_port, uint16_t ext_port)
// TODO handle some errors here
return false;
}
#endif
#else
return false;
#endif
}

bool nat_create_mapping(nat_ctx *ctx, uint16_t int_port, uint16_t ext_port) {
Expand Down
14 changes: 7 additions & 7 deletions src/game/utils/score.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ typedef struct score_text {
} score_text;

float multipliers[] = {
0.2, // punching bag
0.4, // rookie
0.6, // veteran
0.8, // world class
1.0, // champion
1.2, // deadly
1.4 // ultimate
0.2f, // punching bag
0.4f, // rookie
0.6f, // veteran
0.8f, // world class
1.0f, // champion
1.2f, // deadly
1.4f // ultimate
};

vec2i interpolate(vec2i start, vec2i end, float fraction) {
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "utils/msgbox.h"
#include "utils/random.h"
#include <SDL.h>
#if ARGTABLE2_FOUND
#if defined(ARGTABLE2_FOUND)
#include <argtable2.h>
#elif ARGTABLE3_FOUND
#elif defined(ARGTABLE3_FOUND)
#include <argtable3.h>
#endif
#include <enet/enet.h>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <string.h>

#if __APPLE__
#ifdef __APPLE__
// MacOS X does not ship uchar.h
#include <stdint.h>
typedef uint_least16_t char16_t;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/scandir.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#endif

static void check_valid_directory(char const *dir) {
#if !NDEBUG
#ifndef NDEBUG
assert(dir != NULL);
assert(dir[0] != '\0');
size_t end = strlen(dir) - 1;
#if _WIN32
#ifdef _WIN32
assert(dir[end] == '\\');
#else
assert(dir[end] == '/');
Expand Down
2 changes: 1 addition & 1 deletion src/video/renderers/opengl3/helpers/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static GLuint bound_vbo = 0;
static GLuint bound_vao = 0;
static GLuint bound_tex[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static GLuint bound_fbo = 0;
static GLuint active_tex = -1;
static GLuint active_tex = ~0u;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine to set this to just 0, since GL_TEXTURE0 is the default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 must have been some sort of remnant from somewhere ...


void binding_active_tex(GLuint unit_id) {
if(active_tex != unit_id) {
Expand Down
5 changes: 3 additions & 2 deletions src/video/renderers/opengl3/helpers/object_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ bool object_array_get_batch(const object_array *array, object_array_batch *state
}
state->start = state->end;
object_array_blend_mode next;
for(; state->end < array->item_count; state->end++) {
do {
next = array->modes[state->end];
if(next != state->mode)
break;
}
state->end++;
} while(state->end < array->item_count);
*mode = state->mode;
state->mode = next;
return true;
Expand Down
4 changes: 2 additions & 2 deletions testing/test_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ void test_script_get_frame_index(void) {
}

void test_script_get_frame_index_at(void) {
CU_ASSERT(sd_script_get_frame_index_at(NULL, -1) == -1);
CU_ASSERT(sd_script_get_frame_index_at(&script, -1) == -1);
CU_ASSERT(sd_script_get_frame_index_at(NULL, ~0u) == -1);
CU_ASSERT(sd_script_get_frame_index_at(&script, ~0u) == -1);
CU_ASSERT(sd_script_get_frame_index_at(&script, 0) == 0);
CU_ASSERT(sd_script_get_frame_index_at(&script, 99) == 0);
CU_ASSERT(sd_script_get_frame_index_at(&script, 100) == 1);
Expand Down
4 changes: 2 additions & 2 deletions tools/afdiff/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @license MIT
*/

#if ARGTABLE2_FOUND
#if defined(ARGTABLE2_FOUND)
#include <argtable2.h>
#elif ARGTABLE3_FOUND
#elif defined(ARGTABLE3_FOUND)
#include <argtable3.h>
#endif
#include <stdint.h>
Expand Down
4 changes: 2 additions & 2 deletions tools/aftool/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "formats/af.h"
#include "formats/error.h"
#include <SDL.h>
#if ARGTABLE2_FOUND
#if defined(ARGTABLE2_FOUND)
#include <argtable2.h>
#elif ARGTABLE3_FOUND
#elif defined(ARGTABLE3_FOUND)
#include <argtable3.h>
#endif
#include <stdint.h>
Expand Down
4 changes: 2 additions & 2 deletions tools/altpaltool/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#include "formats/altpal.h"
#include "formats/error.h"
#if ARGTABLE2_FOUND
#if defined(ARGTABLE2_FOUND)
#include <argtable2.h>
#elif ARGTABLE3_FOUND
#elif defined(ARGTABLE3_FOUND)
#include <argtable3.h>
#endif
#include <stdint.h>
Expand Down
Loading
Loading