Skip to content

Commit 7985601

Browse files
committed
fix pedantic warnings
The code now compiles under gcc version 11.5.0 with all warnings and pedantic warnings enabled. Fixed a number of problems related arguments of pointers to functions. Attempt to address issue #2: Compile error under Debian.
1 parent 554de1c commit 7985601

File tree

10 files changed

+31
-32
lines changed

10 files changed

+31
-32
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ FSANITIZE+= -fsanitize=vptr
242242
# FSANITIZE+= -fsanitize=nullability-arg
243243
# FSANITIZE+= -fsanitize=nullability-assign
244244
# FSANITIZE+= -fsanitize=nullability-return
245+
# CCWARN+= -Wall
246+
# CCWARN+= -pedantic
245247
# CCWARN+= -Werror
246248
# CFLAGS+= ${FSANITIZE} -fstack-protector-all
247249
# LDFLAGS+= ${FSANITIZE}
@@ -274,6 +276,8 @@ FSANITIZE+= -fsanitize=vptr
274276
#
275277
# dnf install readline-devel ncurses-libs ncurses-devel libasan libubsan
276278
#
279+
# CCWARN+= -Wall
280+
# CCWARN+= -pedantic
277281
# CCWARN+= -Werror
278282
# CFLAGS+= ${FSANITIZE} -fstack-protector-all
279283
# LDFLAGS+= ${FSANITIZE}

daemon.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ d_slot(void)
3939
* Find a particular slot in the table
4040
*/
4141
struct delayed_action *
42-
find_slot(void (*func)())
42+
find_slot(void (*func)(int))
4343
{
4444
struct delayed_action *dev;
4545

@@ -54,7 +54,7 @@ find_slot(void (*func)())
5454
* Start a daemon, takes a function.
5555
*/
5656
void
57-
start_daemon(void (*func)(), int arg, int type)
57+
start_daemon(void (*func)(int), int arg, int type)
5858
{
5959
struct delayed_action *dev;
6060

@@ -70,7 +70,7 @@ start_daemon(void (*func)(), int arg, int type)
7070
* Remove a daemon from the list
7171
*/
7272
void
73-
kill_daemon(void (*func)())
73+
kill_daemon(void (*func)(int))
7474
{
7575
struct delayed_action *dev;
7676

@@ -108,7 +108,7 @@ do_daemons(int flag)
108108
* Start a fuse to go off in a certain number of turns
109109
*/
110110
void
111-
fuse(void (*func)(), int arg, int time, int type)
111+
fuse(void (*func)(int), int arg, int time, int type)
112112
{
113113
struct delayed_action *wire;
114114

@@ -124,7 +124,7 @@ fuse(void (*func)(), int arg, int time, int type)
124124
* Increase the time until a fuse goes off
125125
*/
126126
void
127-
lengthen(void (*func)(), int xtime)
127+
lengthen(void (*func)(int), int xtime)
128128
{
129129
struct delayed_action *wire;
130130

@@ -138,7 +138,7 @@ lengthen(void (*func)(), int xtime)
138138
* Put out a fuse
139139
*/
140140
void
141-
extinguish(void (*func)())
141+
extinguish(void (*func)(int))
142142
{
143143
struct delayed_action *wire;
144144

daemons.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ come_down(void)
239239
* change the characters for the player
240240
*/
241241
void
242-
visuals(void)
242+
visuals(int d_arg __attribute__ ((__unused__)))
243243
{
244244
THING *tp;
245245
int seemonst;

new_level.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ new_level(void)
100100
if (on(player, SEEMONST))
101101
turn_see(FALSE);
102102
if (on(player, ISHALU))
103-
visuals();
103+
visuals(0);
104104
}
105105

106106
/*

potions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ quaff(void)
111111
msg("you feel stronger, now. What bulging muscles!");
112112
when P_MFIND:
113113
player.t_flags |= SEEMONST;
114-
fuse((void(*)())turn_see, TRUE, HUHDURATION, AFTER);
114+
fuse((void(*)(int))turn_see, TRUE, HUHDURATION, AFTER);
115115
if (!turn_see(FALSE))
116116
msg("you have a %s feeling for a moment, then it passes",
117117
choose_str("normal", "strange"));

rip.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void
103103
score(int amount, int flags, int monst)
104104
{
105105
SCORE *scp;
106-
int i;
107106
SCORE *sc2;
108107
SCORE *top_scores, *endp;
109108
# ifdef MASTER

rogue.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ int endmsg(void);
616616
void enter_room(const coord *cp);
617617
void erase_lamp(const coord *pos, const struct room *rp);
618618
int exp_add(const THING *tp);
619-
void extinguish(void (*func)());
619+
void extinguish(void (*func)(int));
620620
void fall(THING *obj, int pr);
621621
int fallpos(const coord *pos, coord *newpos);
622622
void fatal(const char *s);
@@ -629,7 +629,7 @@ int find_floor(const struct room *rp, coord *cp, int limit, int monst);
629629
THING *find_obj(int y, int x);
630630
int fight(const coord *mp, const THING *weap, int thrown);
631631
void fix_stick(THING *cur);
632-
void fuse(void (*func)(), int arg, int time, int type);
632+
void fuse(void (*func)(int), int arg, int time, int type);
633633
int get_bool(void *vp, WINDOW *win);
634634
int get_dir(void);
635635
int get_inv_t(void *vp, WINDOW *win);
@@ -644,7 +644,7 @@ void help(void);
644644
void hit(const char *er, const char *ee, int noend);
645645
void horiz(const struct room *rp, int starty);
646646
void leave_room(const coord *cp);
647-
void lengthen(void (*func)(), int xtime);
647+
void lengthen(void (*func)(int), int xtime);
648648
void look(int wakeup);
649649
int hit_monster(int y, int x, const THING *obj);
650650
void identify(void);
@@ -663,7 +663,7 @@ void invis_on(void);
663663
int is_current(const THING *obj);
664664
int is_magic(const THING *obj);
665665
int is_symlink(const char *sp);
666-
void kill_daemon(void (*func)());
666+
void kill_daemon(void (*func)(int));
667667
void killed(THING *tp, int pr);
668668
const char *killname(int monst, int doart);
669669
void land(void);
@@ -757,7 +757,7 @@ void show_win(const char *message);
757757
void sight(int d_arg);
758758
int sign(int nm);
759759
int spread(int nm);
760-
void start_daemon(void (*func)(), int arg, int type);
760+
void start_daemon(void (*func)(int), int arg, int type);
761761
void start_score(void);
762762
void status(void);
763763
int step_ok(int ch);
@@ -782,7 +782,7 @@ void uncurse(THING *obj);
782782
void unlock_sc(void);
783783
void unsee(int d_arg);
784784
void vert(const struct room *rp, int startx);
785-
void visuals(void);
785+
void visuals(int);
786786
char *vowelstr(const char *str);
787787
void wait_for(WINDOW *win, int ch);
788788
const THING *wake_monster(int y, int x);

save.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,13 @@ restore(const char *file)
164164
struct stat sbuf2;
165165
int lines, cols;
166166

167-
if (strcmp(file, "-r") == 0)
167+
if (strcmp(file, "-r") == 0) {
168168
file = file_name;
169+
}
169170

170-
md_tstphold();
171+
md_tstphold();
171172

172-
if ((inf = fopen(file,"r")) == NULL)
173+
if ((inf = fopen(file,"r")) == NULL)
173174
{
174175
perror(file);
175176
return FALSE;
@@ -375,7 +376,6 @@ rd_score(SCORE *top_score)
375376
{
376377
char scoreline[MAXSCORELINE+1]; /* +1 for paranoia */
377378
SCORE score; /* scanned score */
378-
char *realname = NULL; /* uid converted into username */
379379
bool failed = false; /* true ==> score file scan failed */
380380
int ret; /* scanf return value */
381381
int i;

scedit.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
# define RN (((seed = seed*11109+13849) >> 16) & 0xffff)
2828

29-
# define MAXSTR 80
29+
# define MAXSTR 1024
3030

3131
# include "score.h"
3232
# include "config.h"
@@ -77,8 +77,9 @@ extern char * s_killname(int monst, int doart);
7777
int
7878
main(int ac, char *av[])
7979
{
80-
FILE *outf;
8180
int inf;
81+
size_t scorename_len = 0;
82+
size_t home_len = 0;
8283

8384
memset(top_scores, 0, sizeof(top_scores)); /* paranoia */
8485
if (ac == 1) {
@@ -89,14 +90,16 @@ main(int ac, char *av[])
8990

9091
strncpy(home, md_gethomedir(), MAXSTR);
9192
home[MAXSTR] = '\0'; /* paranoia */
92-
if (strlen(home) > MAXSTR - strlen(SCORENAME) - 1)
93+
scorename_len = strlen(SCORENAME);
94+
home_len = strlen(home);
95+
if (home_len > MAXSTR - scorename_len - 1)
9396
home[0] = '\0';
94-
scorefile = calloc(MAXSTR+1, 1);
97+
scorefile = calloc(MAXSTR+scorename_len+1, 1);
9598
if (scorefile == NULL) {
9699
perror("calloc for scorefile failed");
97100
exit(1);
98101
}
99-
snprintf(scorefile, MAXSTR, "%s%s", home, SCORENAME);
102+
snprintf(scorefile, MAXSTR+scorename_len, "%s%s", home, SCORENAME);
100103
} else {
101104
scorefile = av[1];
102105
}
@@ -126,9 +129,7 @@ main(int ac, char *av[])
126129
int
127130
do_comm(void)
128131
{
129-
char *sp;
130132
SCORE *scp;
131-
struct passwd *pp;
132133
static FILE *outf = NULL;
133134
static int written = TRUE;
134135

@@ -209,7 +210,6 @@ do_comm(void)
209210
void
210211
add_score(void)
211212
{
212-
SCORE *scp;
213213
uid_t id = 0;
214214
int i;
215215
SCORE new;
@@ -327,7 +327,6 @@ void
327327
del_score(void)
328328
{
329329
SCORE *scp;
330-
int i;
331330
int num;
332331

333332
for (;;) {

state.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@
6767
#define READSTAT (format_error || read_error )
6868
#define WRITESTAT (write_error)
6969

70-
static int read_error = FALSE;
71-
static int write_error = FALSE;
72-
static int format_error = FALSE;
7370
static int endian = 0x01020304;
7471
#define big_endian ( *((char *)&endian) == 0x01 )
7572

0 commit comments

Comments
 (0)