Skip to content

Commit 8489941

Browse files
enable more warnings by default, make it compile cleanly with them
1 parent f395d80 commit 8489941

File tree

13 files changed

+296
-244
lines changed

13 files changed

+296
-244
lines changed

Makefile

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ OPTIM ?= 2
2020
CFLAGS = -g -O$(OPTIM) -I./src/ -D_GNU_SOURCE=1 -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DPATCHLEVEL=$(PATCHLEVEL)
2121
LIBS = -lm
2222

23+
# Useful warnings
24+
CFLAGS += -Wall -Wextra -Wpedantic \
25+
-Wformat=2 -Wshadow \
26+
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition \
27+
-Wnested-externs -Wmissing-include-dirs
28+
# GCC warnings that Clang doesn't provide:
29+
ifeq ($(CC),gcc)
30+
CFLAGS += -Wjump-misses-init -Wlogical-op
31+
endif
32+
ifeq ($(CC),clang)
33+
CFLAGS += -Wno-unknown-warning-option
34+
endif
35+
36+
# Ok we still disable some warnings for (hopefully) good reasons
37+
# 1. The debugger uses Xprintf format strings declared as char*, triggering this warning
38+
CFLAGS += -Wno-format-nonliteral
39+
2340
### lua
2441
CFLAGS += $(shell pkg-config --cflags lua)
2542
LIBS += $(shell pkg-config --libs lua)
@@ -29,8 +46,23 @@ CFLAGS += $(shell pkg-config --cflags readline)
2946
LIBS += $(shell pkg-config --libs readline)
3047

3148
FULL_WARNINGS = no
32-
ifeq ($(FULL_WARNINGS), yes)
33-
CFLAGS += -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-unused-function -Wconversion -Wdouble-promotion -Wno-sign-conversion -fsanitize=undefined -fsanitize-trap
49+
ifeq ($(FULL_WARNINGS), no)
50+
CFLAGS += -Wno-unused-variable
51+
CFLAGS += -Wno-unused-parameter
52+
CFLAGS += -Wno-redundant-decls
53+
ifeq ($(CC),gcc)
54+
CFLAGS += -Wno-maybe-uninitialized
55+
CFLAGS += -Wno-discarded-qualifiers
56+
endif
57+
ifeq ($(CC),clang)
58+
CFLAGS += -Wno-uninitialized
59+
CFLAGS += -Wno-ignored-qualifiers
60+
endif
61+
else
62+
CFLAGS += -Wredundant-decls
63+
ifeq ($(CC),clang)
64+
CFLAGS += -Wunused-variable
65+
endif
3466
endif
3567

3668
DOTOS = src/emu_serial.o \

src/config.c

Lines changed: 69 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "config.h"
1717

1818
config_t config = {
19-
.progname = "x48ng",
19+
.progname = ( char* )"x48ng",
2020

2121
.verbose = false,
2222
.print_config = false,
@@ -46,8 +46,8 @@ config_t config = {
4646

4747
/* x11 */
4848
.netbook = false,
49-
.name = "x48ng",
50-
.title = "x48ng",
49+
.name = ( char* )"x48ng",
50+
.title = ( char* )"x48ng",
5151
.x11_visual = NULL,
5252
/* default | staticgray | staticcolor | truecolor | grayscale |
5353
* pseudocolor | directcolor | 0xnn | nn
@@ -61,8 +61,8 @@ config_t config = {
6161
.connFont = NULL,
6262
};
6363

64-
char* configDir = "x48ng";
65-
char* config_file = "config.lua";
64+
char* configDir = ( char* )"x48ng";
65+
char* config_file = ( char* )"config.lua";
6666
char* romFileName = NULL;
6767
char* ramFileName = NULL;
6868
char* stateFileName = NULL;
@@ -253,7 +253,7 @@ int config_init( int argc, char* argv[] )
253253
int clopt_leave_shift_keys = -1;
254254
int clopt_inhibit_shutdown = -1;
255255

256-
char* optstring = "c:hvVtsirT";
256+
const char* optstring = "c:hvVtsirT";
257257
struct option long_options[] = {
258258
{"config", required_argument, NULL, 'c' },
259259
{"config-dir", required_argument, NULL, 1000 },
@@ -304,67 +304,67 @@ int config_init( int argc, char* argv[] )
304304
{0, 0, 0, 0 }
305305
};
306306

307-
char* help_text = "usage: %s [options]\n"
308-
"options:\n"
309-
" -h --help what you are reading\n"
310-
" -v --version show version\n"
311-
" --print-config print configuration as config file\n"
312-
" -c --config=<path> use <path> as x48ng's config file (default: "
313-
"$XDG_CONFIG_HOME/x48ng/config.lua)\n"
314-
" --config-dir=<path> use <path> as x48ng's home (default: "
315-
"$XDG_CONFIG_HOME/x48ng/)\n"
316-
" --rom=<filename> use <filename> (absolute or relative to "
317-
"<config-dir>) as ROM (default: rom)\n"
318-
" --ram=<filename> use <filename> (absolute or relative to "
319-
"<config-dir>) as RAM (default: ram)\n"
320-
" --state=<filename> use <filename> (absolute or relative "
321-
"to <config-dir>) as STATE (default: hp48)\n"
322-
" --port1=<filename> use <filename> (absolute or relative "
323-
"to <config-dir>) as PORT1 (default: port1)\n"
324-
" --port2=<filename> use <filename> (absolute or relative "
325-
"to <config-dir>) as PORT2 (default: port2)\n"
326-
" --serial-line=<path> use <path> as serial device default: "
327-
"%s)\n"
328-
" -V --verbose be verbose (default: false)\n"
329-
" --x11 use X11 front-end (default: true)\n"
330-
" --sdl use SDL front-end (default: false)\n"
331-
" --tui use text front-end (default: false)\n"
332-
" --tui-small use text small front-end (2×2 pixels per character) (default: "
333-
"false)\n"
334-
" --tui-tiny use text tiny front-end (2×4 pixels per character) (default: "
335-
"false)\n"
336-
" -t --use-terminal activate pseudo terminal interface (default: "
337-
"true)\n"
338-
" -s --use-serial activate serial interface (default: false)\n"
339-
" --debug enable the debugger\n"
340-
" -r --reset perform a reset on startup\n"
341-
" -T --throttle try to emulate real speed (default: false)\n"
342-
" --no-chrome only display the LCD (default: "
343-
"false)\n"
344-
" --fullscreen make the UI fullscreen "
345-
"(default: false)\n"
346-
" --netbook make the UI horizontal (default: "
347-
"false)\n"
348-
" --visual=<X visual> use x11 visual <X visual> (default: "
349-
"default), possible values: "
350-
"<default | staticgray | staticcolor | truecolor | grayscale | "
351-
"pseudocolor | directcolor | 0xnn | nn>\n"
352-
" --small-font=<font> use <X font name> as small "
353-
"font (default: %s)\n"
354-
" --medium-font=<font> use <X font name> as medium "
355-
"font (default: %s)\n"
356-
" --large-font=<font> use <X font name> as large "
357-
"font (default: %s)\n"
358-
" --connection-font=<font> use <X font name> as "
359-
"connection font (default: %s)\n"
360-
" --mono make the UI monochrome (default: "
361-
"false)\n"
362-
" --gray make the UI grayscale (default: "
363-
"false)\n"
364-
" --leave-shift-keys _not_ mapping the shift keys to let them free for numbers (default: "
365-
"false)\n"
366-
" --inhibit-shutdown __tentative fix for stuck-on-OFF bug__ (default: "
367-
"false)\n";
307+
const char* help_text = "usage: %s [options]\n"
308+
"options:\n"
309+
" -h --help what you are reading\n"
310+
" -v --version show version\n"
311+
" --print-config print configuration as config file\n"
312+
" -c --config=<path> use <path> as x48ng's config file (default: "
313+
"$XDG_CONFIG_HOME/x48ng/config.lua)\n"
314+
" --config-dir=<path> use <path> as x48ng's home (default: "
315+
"$XDG_CONFIG_HOME/x48ng/)\n"
316+
" --rom=<filename> use <filename> (absolute or relative to "
317+
"<config-dir>) as ROM (default: rom)\n"
318+
" --ram=<filename> use <filename> (absolute or relative to "
319+
"<config-dir>) as RAM (default: ram)\n"
320+
" --state=<filename> use <filename> (absolute or relative "
321+
"to <config-dir>) as STATE (default: hp48)\n"
322+
" --port1=<filename> use <filename> (absolute or relative "
323+
"to <config-dir>) as PORT1 (default: port1)\n"
324+
" --port2=<filename> use <filename> (absolute or relative "
325+
"to <config-dir>) as PORT2 (default: port2)\n"
326+
" --serial-line=<path> use <path> as serial device default: "
327+
"%s)\n"
328+
" -V --verbose be verbose (default: false)\n"
329+
" --x11 use X11 front-end (default: true)\n"
330+
" --sdl use SDL front-end (default: false)\n"
331+
" --tui use text front-end (default: false)\n"
332+
" --tui-small use text small front-end (2×2 pixels per character) (default: "
333+
"false)\n"
334+
" --tui-tiny use text tiny front-end (2×4 pixels per character) (default: "
335+
"false)\n"
336+
" -t --use-terminal activate pseudo terminal interface (default: "
337+
"true)\n"
338+
" -s --use-serial activate serial interface (default: false)\n"
339+
" --debug enable the debugger\n"
340+
" -r --reset perform a reset on startup\n"
341+
" -T --throttle try to emulate real speed (default: false)\n"
342+
" --no-chrome only display the LCD (default: "
343+
"false)\n"
344+
" --fullscreen make the UI fullscreen "
345+
"(default: false)\n"
346+
" --netbook make the UI horizontal (default: "
347+
"false)\n"
348+
" --visual=<X visual> use x11 visual <X visual> (default: "
349+
"default), possible values: "
350+
"<default | staticgray | staticcolor | truecolor | grayscale | "
351+
"pseudocolor | directcolor | 0xnn | nn>\n"
352+
" --small-font=<font> use <X font name> as small "
353+
"font (default: %s)\n"
354+
" --medium-font=<font> use <X font name> as medium "
355+
"font (default: %s)\n"
356+
" --large-font=<font> use <X font name> as large "
357+
"font (default: %s)\n"
358+
" --connection-font=<font> use <X font name> as "
359+
"connection font (default: %s)\n"
360+
" --mono make the UI monochrome (default: "
361+
"false)\n"
362+
" --gray make the UI grayscale (default: "
363+
"false)\n"
364+
" --leave-shift-keys _not_ mapping the shift keys to let them free for numbers (default: "
365+
"false)\n"
366+
" --inhibit-shutdown __tentative fix for stuck-on-OFF bug__ (default: "
367+
"false)\n";
368368
while ( c != EOF ) {
369369
c = getopt_long( argc, argv, optstring, long_options, &option_index );
370370

@@ -424,13 +424,15 @@ int config_init( int argc, char* argv[] )
424424
break;
425425
case 9109:
426426
fprintf( stdout, "`--small` is deprecated, please use `--tui-small` instead of `--tui --small`" );
427+
/* break; */ /* intentional fall-through */
427428
case 9110:
428429
clopt_frontend_type = FRONTEND_TEXT;
429430
clopt_small = true;
430431
clopt_tiny = false;
431432
break;
432433
case 9119:
433434
fprintf( stdout, "`--tiny` is deprecated, please use `--tui-tiny` instead of `--tui --tiny`" );
435+
/* break; */ /* intentional fall-through */
434436
case 9120:
435437
clopt_frontend_type = FRONTEND_TEXT;
436438
clopt_small = false;

src/debugger.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,6 @@ static char* dec_string( word_20* addr, char* string )
22272227
static char* dec_hex_string( word_20* addr, char* string )
22282228
{
22292229
int len, lead, i, n;
2230-
static char hex[] = "0123456789ABCDEF";
22312230
char* p = string;
22322231

22332232
len = read_nibbles( *addr, 5 );
@@ -2239,7 +2238,7 @@ static char* dec_hex_string( word_20* addr, char* string )
22392238
*p++ = ' ';
22402239
lead = 1;
22412240
for ( i = len - 1; i >= 0; i-- ) {
2242-
*p = hex[ read_nibble( *addr + i ) ];
2241+
*p = hex[ disassembler_mode ][ read_nibble( *addr + i ) ];
22432242
if ( lead ) {
22442243
if ( ( i != 0 ) && ( *p == '0' ) )
22452244
p--;
@@ -2265,7 +2264,7 @@ static char* dec_hex_string( word_20* addr, char* string )
22652264
n = 1000;
22662265

22672266
for ( i = 0; i < n; i++ )
2268-
*p++ = hex[ read_nibble( *addr + i ) ];
2267+
*p++ = hex[ disassembler_mode ][ read_nibble( *addr + i ) ];
22692268

22702269
if ( n != len ) {
22712270
*p++ = '.';
@@ -2767,17 +2766,16 @@ static char* dec_acptr( word_20* addr, char* string )
27672766
word_20 size;
27682767
char* p = string;
27692768
int i;
2770-
static char hex[] = "0123456789ABCDEF";
27712769

27722770
if ( opt_gx ) {
27732771
size = 10;
27742772
sprintf( p, "ACPTR " );
27752773
p += strlen( p );
27762774
for ( i = 0; i < 5; i++ )
2777-
*p++ = hex[ read_nibble( *addr + i ) ];
2775+
*p++ = hex[ disassembler_mode ][ read_nibble( *addr + i ) ];
27782776
*p++ = ' ';
27792777
for ( i = 5; i < 10; i++ )
2780-
*p++ = hex[ read_nibble( *addr + i ) ];
2778+
*p++ = hex[ disassembler_mode ][ read_nibble( *addr + i ) ];
27812779
} else {
27822780
size = read_nibbles( *addr, 5 );
27832781
sprintf( p, "Ext 1" );

src/emu_emulate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2386,7 +2386,7 @@ static inline int decode_8_thru_f( int op1 )
23862386
}
23872387
}
23882388

2389-
inline int step_instruction( void )
2389+
int step_instruction( void )
23902390
{
23912391
int op0, op1, op2, op3;
23922392
int stop = 0;

src/emu_init.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ bool please_exit = false;
2222
bool save_before_exit = true;
2323

2424
bool rom_is_new = true;
25-
long ram_size;
2625
long port1_size;
2726
long port1_mask;
2827
bool port1_is_ram;
@@ -463,8 +462,9 @@ int read_mem_file( char* name, word_4* mem, int size )
463462

464463
int read_files( void )
465464
{
466-
unsigned long v1, v2;
467-
int i, read_version;
465+
/* unsigned long v1, v2; */
466+
int i;
467+
bool read_version;
468468
int ram_size;
469469
struct stat st;
470470
FILE* fp;
@@ -506,30 +506,30 @@ int read_files( void )
506506
/*
507507
* MAGIC ok, read and compare the version
508508
*/
509-
read_version = 1;
509+
read_version = true;
510510
for ( i = 0; i < 4; i++ ) {
511511
if ( !read_char( fp, &saturn.version[ i ] ) ) {
512512
if ( config.verbose )
513513
fprintf( stderr, "can\'t read version\n" );
514-
read_version = 0;
514+
read_version = false;
515515
}
516516
}
517517

518518
if ( read_version ) {
519-
v1 = ( ( int )saturn.version[ 0 ] & 0xff ) << 24;
520-
v1 |= ( ( int )saturn.version[ 1 ] & 0xff ) << 16;
521-
v1 |= ( ( int )saturn.version[ 2 ] & 0xff ) << 8;
522-
v1 |= ( ( int )saturn.version[ 3 ] & 0xff );
523-
v2 = ( ( int )VERSION_MAJOR & 0xff ) << 24;
524-
v2 |= ( ( int )VERSION_MINOR & 0xff ) << 16;
525-
v2 |= ( ( int )PATCHLEVEL & 0xff ) << 8;
519+
/* v1 = ( ( int )saturn.version[ 0 ] & 0xff ) << 24; */
520+
/* v1 |= ( ( int )saturn.version[ 1 ] & 0xff ) << 16; */
521+
/* v1 |= ( ( int )saturn.version[ 2 ] & 0xff ) << 8; */
522+
/* v1 |= ( ( int )saturn.version[ 3 ] & 0xff ); */
523+
/* v2 = ( ( int )VERSION_MAJOR & 0xff ) << 24; */
524+
/* v2 |= ( ( int )VERSION_MINOR & 0xff ) << 16; */
525+
/* v2 |= ( ( int )PATCHLEVEL & 0xff ) << 8; */
526526

527527
/*
528528
* try to read latest version file
529529
*/
530530
if ( !read_state_file( fp ) ) {
531531
if ( config.verbose )
532-
fprintf( stderr, "can\'t handle %s\n", normalized_state_path );
532+
fprintf( stderr, "can't handle %s\n", normalized_state_path );
533533
init_saturn();
534534
} else if ( config.verbose )
535535
printf( "read %s\n", normalized_state_path );

src/emu_serial.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ void serial_baud( int baud )
185185
}
186186

187187
#if !defined( __APPLE__ )
188+
# pragma GCC diagnostic push // save the actual diag context
189+
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // disable maybe warnings
190+
# pragma GCC diagnostic ignored "-Wuninitialized" // disable maybe warnings
188191
ttybuf.c_cflag &= ~CBAUD;
192+
# pragma GCC diagnostic pop // restore previous diag context
189193
#endif
190194
baud &= 0x7;
191195
switch ( baud ) {

src/tools/dump2rom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ unsigned char* core;
99

1010
#define DEFAULT_ROM_FILE "rom.dump"
1111

12-
bool write_mem_file( char* name, unsigned char* mem, size_t size )
12+
bool write_mem_file( const char* name, unsigned char* mem, size_t size )
1313
{
1414
FILE* fp;
1515
unsigned char* tmp_mem;

src/tools/mkcard.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include <unistd.h>
66
#include <stdbool.h>
77

8-
unsigned char* mem;
9-
108
bool write_mem_file( char* name, unsigned char* mem, size_t size )
119
{
1210
FILE* fp;

src/ui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void start_UI( int argc, char** argv )
200200
}
201201
}
202202

203-
void ui_stop()
203+
void ui_stop( void )
204204
{
205205
ui_init_LCD();
206206

0 commit comments

Comments
 (0)