more strict warnings; fixed some subtle bugs

This commit is contained in:
Andrei Alexeyev 2017-11-11 19:32:22 +02:00
parent 826aa626ff
commit b61ef0bffc
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
15 changed files with 62 additions and 38 deletions

View file

@ -222,9 +222,31 @@ if(${HAVE_BACKTRACE})
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DLOG_ENABLE_BACKTRACE")
endif()
set(WARNINGS "-Wall -Wno-parentheses -Wtype-limits -Wstrict-prototypes -Wlong-long -Winit-self")
CHECK_AND_SET_FLAGS(COMPILER_WARN_PEDANTIC "-Wpedantic" WARNINGS)
CHECK_AND_SET_FLAGS(COMPILER_WARN_NULLDEREF "-Wnull-dereference" WARNINGS)
set(WANT_WARNINGS
"all"
"pedantic"
"parentheses"
"type-limits"
"strict-prototypes"
"long-long"
"init-self"
"null-dereference"
"format-pedantic"
"gcc-compat"
"float-overflow-conversion"
"float-zero-conversion"
"for-loop-analysis"
"implicit-fallthrough"
"sometimes-uninitialized"
"unneeded-internal-declaration"
"unreachable-code"
"unreachable-code-loop-increment"
"gnu"
)
foreach(warning IN LISTS WANT_WARNINGS)
CHECK_AND_SET_FLAGS(COMPILER_HAS_W${warning} "-W${warning}" WARNINGS)
endforeach()
if(RELATIVE)
add_definitions(-DRELATIVE)

View file

@ -96,7 +96,7 @@ static bool events_invoke_handlers(SDL_Event *event, ListContainer *h_list, Even
// case 1 (simplest): we have a list and no custom handlers
for(ListContainer *c = h_list; c; c = c->next) {
if(result = events_invoke_handler(event, (EventHandler*)c->data)) {
if((result = events_invoke_handler(event, (EventHandler*)c->data))) {
break;
}
}
@ -139,7 +139,7 @@ static bool events_invoke_handlers(SDL_Event *event, ListContainer *h_list, Even
// iterate over the merged list
for(ListContainer *c = merged_list; c; c = c->next) {
if(result = events_invoke_handler(event, (EventHandler*)c->data)) {
if((result = events_invoke_handler(event, (EventHandler*)c->data))) {
break;
}
}
@ -152,7 +152,7 @@ static bool events_invoke_handlers(SDL_Event *event, ListContainer *h_list, Even
// case 3 (unlikely): we don't have a list for some reason (no global handlers?), but there are custom handlers
for(EventHandler *h = h_array; h->proc; ++h) {
if(result = events_invoke_handler(event, h)) {
if((result = events_invoke_handler(event, h))) {
break;
}
}

View file

@ -218,7 +218,8 @@ void spawn_items(complex pos, ...) {
va_start(args, pos);
ItemType type;
while(type = va_arg(args, ItemType)) {
while((type = va_arg(args, ItemType))) {
int num = va_arg(args, int);
for(int i = 0; i < num; ++i) {
spawn_item(pos, type);

View file

@ -641,7 +641,6 @@ static void progress_write(SDL_RWops *file) {
if(!SDL_RWwrite(file, buf, bufsize, 1)) {
log_fatal("SDL_RWwrite() failed: %s", SDL_GetError());
free(buf);
return;
}

View file

@ -270,7 +270,7 @@ void wrap_text(char *buf, size_t bufsize, const char *src, int width, TTF_Font *
strcpy(src_copy, src);
*buf = 0;
while(next = strtok_r(NULL, " \t\n", &sptr)) {
while((next = strtok_r(NULL, " \t\n", &sptr))) {
int curwidth;
if(!*next) {

View file

@ -159,10 +159,10 @@ static int stage3_slavefairy2(Enemy *e, int t) {
}
complex dir = cexp(I*a);
PROJECTILE("wave", e->pos, _i&1 ? rgb(1.0,0.3,0.3): rgb(0.3,0.3,1.0), linear, { 2*dir });
PROJECTILE("wave", e->pos, (_i&1) ? rgb(1.0,0.3,0.3) : rgb(0.3,0.3,1.0), linear, { 2*dir });
if(global.diff > D_Normal && _i % 3 == 0) {
PROJECTILE("rice", e->pos, _i&1==0 ? rgb(1.0,0.3,0.3): rgb(0.3,0.3,1.0), linear, { -2*dir });
PROJECTILE("rice", e->pos, !(_i&1) ? rgb(1.0,0.3,0.3) : rgb(0.3,0.3,1.0), linear, { -2*dir });
}
}

View file

@ -56,6 +56,7 @@ static int fall_over;
enum {
NUM_STARS = 100
};
static float starpos[3*NUM_STARS];
Vector **stage6_towerwall_pos(Vector pos, float maxrange) {
@ -213,15 +214,17 @@ void stage6_start(void) {
for(int i = 0; i < NUM_STARS; i++) {
float x,y,z,r;
do {
x = nfrand();
y = nfrand();
z = frand();
r = sqrt(x*x+y*y+z*z);
} while(0 < r < 1);
starpos[3*i+0]= x/r;
starpos[3*i+1]= y/r;
starpos[3*i+2]= z/r;
} while(r <= 0 || r > 1);
starpos[3*i+0] = x/r;
starpos[3*i+1] = y/r;
starpos[3*i+2] = z/r;
}
bgcontext.cx[1] = -230;

View file

@ -62,7 +62,7 @@ static bool extension_supported(const char *ext) {
strcpy(buf, overrides);
arg = buf;
while(e = strtok_r(arg, " ", &save)) {
while((e = strtok_r(arg, " ", &save))) {
bool r = true;
if(*e == '-') {
@ -82,20 +82,20 @@ static bool extension_supported(const char *ext) {
}
static void check_glext_draw_instanced(void) {
if(glext.draw_instanced = (
if((glext.draw_instanced = (
(glext.ARB_draw_instanced = extension_supported("GL_ARB_draw_instanced")) &&
(glext.DrawArraysInstanced = tsglDrawArraysInstancedARB)
)) {
))) {
log_debug("Using GL_ARB_draw_instanced");
return;
} else {
glext.ARB_draw_instanced = false;
}
if(glext.draw_instanced = (
if((glext.draw_instanced = (
(glext.EXT_draw_instanced = extension_supported("GL_EXT_draw_instanced")) &&
(glext.DrawArraysInstanced = tsglDrawArraysInstancedARB)
)) {
))) {
log_debug("Using GL_EXT_draw_instanced");
return;
} else {
@ -110,20 +110,20 @@ static void check_glext_draw_instanced(void) {
}
static void check_glext_debug_output(void) {
if(glext.debug_output = (
if((glext.debug_output = (
extension_supported("GL_ARB_debug_output") &&
(glext.DebugMessageCallback = tsglDebugMessageCallbackARB) &&
(glext.DebugMessageControl = tsglDebugMessageControlARB)
)) {
))) {
log_debug("Using GL_ARB_debug_output");
return;
}
if(glext.debug_output = (
if((glext.debug_output = (
extension_supported("GL_KHR_debug") &&
(glext.DebugMessageCallback = tsglDebugMessageCallback) &&
(glext.DebugMessageControl = tsglDebugMessageControl)
)) {
))) {
log_debug("Using GL_KHR_debug");
return;
}

View file

@ -68,7 +68,7 @@ void vfs_path_split_left(char *path, char **lpath, char **rpath) {
*lpath = path;
if(sep = strchr(path, VFS_PATH_SEP)) {
if((sep = strchr(path, VFS_PATH_SEP))) {
*sep = 0;
*rpath = sep + 1;
} else {
@ -83,7 +83,7 @@ void vfs_path_split_right(char *path, char **lpath, char **rpath) {
while(*(c = strrchr(path, 0) - 1) == VFS_PATH_SEP)
*c = 0;
if(sep = strrchr(path, VFS_PATH_SEP)) {
if((sep = strrchr(path, VFS_PATH_SEP))) {
*sep = 0;
*lpath = path;
*rpath = sep + 1;

View file

@ -167,7 +167,7 @@ bool vfs_mount(VFSNode *root, const char *mountpoint, VFSNode *subtree) {
strcpy(buf[1], buf[0]);
vfs_path_split_right(buf[1], &mpbase, &mpname);
if(mpnode = vfs_locate(root, mountpoint)) {
if((mpnode = vfs_locate(root, mountpoint))) {
// mountpoint already exists - try to merge with the target node
if(mpnode->funcs->mount) {
@ -182,7 +182,7 @@ bool vfs_mount(VFSNode *root, const char *mountpoint, VFSNode *subtree) {
return result;
}
if(mpnode = vfs_locate(root, mpbase)) {
if((mpnode = vfs_locate(root, mpbase))) {
// try to become a subnode of parent (conventional mount)
if(mpnode->funcs->mount) {
@ -229,7 +229,7 @@ char* vfs_repr_node(VFSNode *node, bool try_syspath) {
char *r;
if(try_syspath && node->funcs->syspath) {
if(r = node->funcs->syspath(node)) {
if((r = node->funcs->syspath(node))) {
return r;
}
}
@ -259,7 +259,7 @@ void vfs_print_tree_recurse(SDL_RWops *dest, VFSNode *root, char *prefix, const
return;
}
for(const char *n; n = vfs_iter(root, &o);) {
for(const char *n; (n = vfs_iter(root, &o));) {
VFSNode *node = vfs_locate(root, n);
if(node) {
vfs_print_tree_recurse(dest, node, newprefix, n);

View file

@ -229,7 +229,7 @@ char** vfs_dir_list_sorted(const char *path, size_t *out_size, int (*compare)(co
results = malloc(sizeof(char*) * real_size);
*out_size = 0;
for(const char *e; e = vfs_dir_read(dir);) {
for(const char *e; (e = vfs_dir_read(dir));) {
if(filter && !filter(e)) {
continue;
}

View file

@ -49,7 +49,7 @@ static SDL_RWops* vfs_syspath_open(VFSNode *node, VFSOpenMode mode) {
static VFSNode* vfs_syspath_locate(VFSNode *node, const char *path) {
VFSNode *n = vfs_alloc();
vfs_syspath_init_internal(n, strfmt("%s%c%s", node->_path_, VFS_PATH_SEP, path));
vfs_syspath_init_internal(n, strfmt("%s%c%s", (char*)node->_path_, VFS_PATH_SEP, path));
return n;
}
@ -86,7 +86,7 @@ static void vfs_syspath_iter_stop(VFSNode *node, void **opaque) {
}
static char* vfs_syspath_repr(VFSNode *node) {
return strfmt("filesystem path (posix): %s", node->_path_);
return strfmt("filesystem path (posix): %s", (char*)node->_path_);
}
static char* vfs_syspath_syspath(VFSNode *node) {
@ -100,7 +100,7 @@ static bool vfs_syspath_mkdir(VFSNode *node, const char *subdir) {
subdir = "";
}
char *p = strfmt("%s%c%s", node->_path_, VFS_PATH_SEP, subdir);
char *p = strfmt("%s%c%s", (char*)node->_path_, VFS_PATH_SEP, subdir);
bool ok = !mkdir(p, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if(!ok && errno == EEXIST) {

View file

@ -28,7 +28,7 @@ static VFSNode* vfs_vdir_locate(VFSNode *vdir, const char *path) {
strcpy(mutpath, path);
vfs_path_split_left(mutpath, &primpath, &subpath);
if(node = hashtable_get_string(vdir->_contents_, mutpath)) {
if((node = hashtable_get_string(vdir->_contents_, mutpath))) {
return vfs_locate(node, subpath);
}

View file

@ -272,7 +272,6 @@ static void video_new_window_internal(int w, int h, uint32_t flags, bool fallbac
return;
}
log_fatal("Failed to create window with mode %ix%i (%s): %s", w, h, modeflagsstr(flags), SDL_GetError());
video_new_window_internal(RESX, RESY, flags & ~SDL_WINDOW_FULLSCREEN_DESKTOP, true);
}

View file

@ -15,8 +15,8 @@
#include <stdbool.h>
#define WINFLAGS_IS_FULLSCREEN(f) ((f) & SDL_WINDOW_FULLSCREEN_DESKTOP)
#define WINFLAGS_IS_FAKE_FULLSCREEN(f) ((f) & SDL_WINDOW_FULLSCREEN_DESKTOP == SDL_WINDOW_FULLSCREEN_DESKTOP)
#define WINFLAGS_IS_REAL_FULLSCREEN(f) ((f) & SDL_WINDOW_FULLSCREEN_DESKTOP == SDL_WINDOW_FULLSCREEN)
#define WINFLAGS_IS_FAKE_FULLSCREEN(f) (WINFLAGS_IS_FULLSCREEN(f) == SDL_WINDOW_FULLSCREEN_DESKTOP)
#define WINFLAGS_IS_REAL_FULLSCREEN(f) (WINFLAGS_IS_FULLSCREEN(f) == SDL_WINDOW_FULLSCREEN)
typedef struct VideoMode {
int width;