clear up a few gcc warnings

This commit is contained in:
nhmall
2022-12-05 23:19:38 -05:00
parent afef4bc781
commit 215808abd1
10 changed files with 165 additions and 95 deletions

View File

@@ -59,6 +59,13 @@ INTERNET_AVAILABLE = N
GIT_AVAILABLE = N
#
#---------------------------------------------------------------
# Do you want to turn on the same gcc warnings as on Unix builds?
#
GCC_EXTRA_WARNINGS = N
#
#===============================================
#======= End of Modification Section ===========
@@ -289,6 +296,20 @@ else
DLBFLG =
endif
ifeq "$(GCC_EXTRA_WARNINGS)" "Y"
#
# These match the warnings enabled on the linux.370 and macOS.370 hints builds
#
CFLAGSXTRA = -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type \
-Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -pedantic \
-Wmissing-declarations -Wformat-nonliteral -Wunreachable-code \
-Wimplicit -Wimplicit-function-declaration -Wimplicit-int \
-Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes
CPPFLAGSXTRA = -Wall -Wextra -Wno-missing-field-initializers -Wreturn-type \
-Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -pedantic \
-Wmissing-declarations -Wformat-nonliteral -Wunreachable-code
endif
COMMONDEF = -DWIN32 -DWINVER=0x0601 -D_WIN32_WINNT=0x0601
DLLDEF = $(COMMONDEF) -D_WINDOWS -D_USRDLL -D_WINDLL
CONSOLEDEF = $(COMMONDEF) -D_CONSOLE
@@ -727,7 +748,8 @@ COREOBJS = $(addsuffix .o, allmain alloc apply artifact attrib ball bones botl c
teleport timeout topten track trap u_init uhitm utf8map vault version vision \
weapon were wield windmain windows windsys wizard worm worn write zap)
CFLAGSW = $(CFLAGS) $(COMMONDEF) $(DLBFLG) -DTILES -D_WINDOWS -DMSWIN_GRAPHICS -DSAFEPROCS -DNOTTYGRAPHICS
CFLAGSW = $(CFLAGS) $(CFLAGSXTRA) $(COMMONDEF) $(DLBFLG) -DTILES -D_WINDOWS -DMSWIN_GRAPHICS -DSAFEPROCS -DNOTTYGRAPHICS
CPPFLAGSW = $(CFLAGS) $(CPPFLAGSXTRA) $(COMMONDEF) $(DLBFLG) -DTILES -D_WINDOWS -DMSWIN_GRAPHICS -DSAFEPROCS -DNOTTYGRAPHICS
ONHW = $(O)nethackw
NHWONLY = $(addsuffix .o, mhaskyn mhdlg mhfont mhinput mhmain mhmap mhmenu \
@@ -759,7 +781,10 @@ $(ONHW)/date.o: $(SRC)/date.c $(NHWOBJS) | $(ONHW)
$(cc) $(CFLAGSW) $(GITHASH) $(GITBRANCH) $< -o$@
$(ONHW)/cppregex.o: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONHW)
$(cc) $(CFLAGSW) $< -o$@
$(cc) $(CPPFLAGSW) $< -o$@
$(ONH)/cppregex.o: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONH)
$(cc) $(CPPFLAGSNH) $< -o$@
$(ONHW)/%.o: $(SSYS)/%.c $(NHLUAH) | $(ONHW)
$(cc) $(CFLAGSW) $< -o$@
@@ -792,7 +817,8 @@ CLEAN_FILE += $(NHWTARGETS) $(NHWOBJS) $(NHWRES) $(BMPS)
#==========================================
# nethack
#==========================================
CFLAGSNH = $(CFLAGSU) -DNO_TILE_C -DSAFEPROCS -D_LIB -DWIN32CON
CFLAGSNH = $(CFLAGSU) $(CFLAGSXTRA) -DNO_TILE_C -DSAFEPROCS -D_LIB -DWIN32CON
CPPFLAGSNH = $(CFLAGSU) $(CPPFLAGSXTRA) -DNO_TILE_C -DSAFEPROCS -D_LIB -DWIN32CON
ONH = $(O)nethack
@@ -827,7 +853,7 @@ $(ONH)/date.o: $(SRC)/date.c $(NHOBJS) $(NHRES) | $(ONH)
$(cc) $(CFLAGSNH) $(GITHASH) $(GITBRANCH) $< -o$@
$(ONH)/cppregex.o: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONH)
$(cc) $(CFLAGSNH) $< -o$@
$(cc) $(CPPFLAGSNH) $< -o$@
$(ONH)/%.o: $(SSYS)/%.c $(NHLUAH) | $(ONH)
$(cc) $(CFLAGSNH) $< -o$@

View File

@@ -61,7 +61,7 @@ $(ONHW)/%.d: $(SRC)/%.c $(NHLUAH) | $(ONHW)
$(cce) $(CFLAGSW) $< -o$@
$(ONHW)/cppregex.d: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONHW)
$(cce) $(CFLAGSW) $< -o$@
$(cce) $(CPPFLAGSW) $< -o$@
$(ONHW)/%.d: $(SSYS)/%.c $(NHLUAH) | $(ONHW)
$(cce) $(CFLAGSW) $< -o$@
@@ -79,7 +79,7 @@ $(ONH)/%.d: $(SRC)/%.c $(NHLUAH) | $(ONH)
$(cce) $(CFLAGSNH) $< -o$@
$(ONH)/cppregex.d: $(SSYS)/cppregex.cpp $(NHLUAH) | $(ONH)
$(cce) $(CFLAGSNH) $< -o$@
$(cce) $(CPPFLAGSNH) $< -o$@
$(ONH)/%.d: $(SSYS)/%.c $(NHLUAH) | $(ONH)
$(cce) $(CFLAGSNH) $< -o$@

View File

@@ -17,7 +17,7 @@
#ifdef USER_SOUNDS
void
play_usersound(const char* filename, int volume)
play_usersound(const char* filename, int volume UNUSED)
{
/* pline("play_usersound: %s (%d).", filename, volume); */
(void) sndPlaySound(filename, SND_ASYNC | SND_NODEFAULT);

View File

@@ -15,7 +15,7 @@ typedef struct {
int left; // in desktop coordinate pixel space
} MonitorInfo;
void win10_init();
void win10_init(void);
int win10_monitor_dpi(HWND hWnd);
double win10_monitor_scale(HWND hWnd);
void win10_monitor_info(HWND hWnd, MonitorInfo * monitorInfo);

View File

@@ -100,6 +100,28 @@ static struct stat hbuf;
extern char orgdir[];
int get_known_folder_path(const KNOWNFOLDERID * folder_id,
char * path, size_t path_size);
void create_directory(const char * path);
int build_known_folder_path(const KNOWNFOLDERID * folder_id,
char * path, size_t path_size, boolean versioned);
void build_environment_path(const char * env_str, const char * folder,
char * path, size_t path_size);
boolean folder_file_exists(const char * folder, const char * file_name);
boolean test_portable_config(const char *executable_path,
char *portable_device_path, size_t portable_device_path_size);
void set_default_prefix_locations(const char *programPath);
void copy_sysconf_content(void);
void copy_config_content(void);
void copy_hack_content(void);
#ifdef PORT_HELP
void port_help(void);
#endif
void windows_raw_print(const char* str);
DISABLE_WARNING_UNREACHABLE_CODE
int
@@ -125,7 +147,8 @@ get_known_folder_path(
// silently handle this problem
return FALSE;
} else if (err != 0) {
error("Failed folder (%u) path string conversion, unexpected err = %d", folder_id->Data1, err);
error("Failed folder (%lu) path string conversion, unexpected err = %d",
folder_id->Data1, err);
return FALSE;
}
@@ -156,7 +179,7 @@ build_known_folder_path(
strcat(path, "\\NetHack\\");
create_directory(path);
if (versioned) {
Sprintf(eos(path), "%d.%d\\",
Sprintf(eos(path), "%d.%d\\",
VERSION_MAJOR, VERSION_MINOR);
create_directory(path);
}
@@ -226,7 +249,7 @@ test_portable_config(
*/
*portable_device_path = '\0';
lth = sizeof tmppath - strlen(sysconf);
lth = sizeof tmppath - strlen(sysconf);
(void) strncpy(tmppath, executable_path, lth - 1);
tmppath[lth - 1] = '\0';
(void) strcat(tmppath, sysconf);
@@ -260,14 +283,14 @@ const char *get_portable_device(void)
}
void
set_default_prefix_locations(const char *programPath)
set_default_prefix_locations(const char *programPath UNUSED)
{
static char executable_path[MAX_PATH];
static char profile_path[MAX_PATH];
static char versioned_profile_path[MAX_PATH];
static char versioned_user_data_path[MAX_PATH];
static char versioned_global_data_path[MAX_PATH];
static char versioninfo[20];
/* static char versioninfo[20] UNUSED; */
strcpy(executable_path, get_executable_path());
append_slash(executable_path);
@@ -594,7 +617,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
load_symset("RogueEpyx", ROGUESET);
}
/* Has the callback for the symset been invoked? Config file processing to
load a symset runs too early to accomplish that because
load a symset runs too early to accomplish that because
the various *graphics_mode_callback pointers don't get set until
term_start_screen, unfortunately */
#if defined(TERMLIB) || defined(CURSES_GRAPHICS)
@@ -1005,7 +1028,7 @@ fakeconsole(void)
}
has_fakeconsole = TRUE;
}
/* Obtain handles for the standard Console I/O devices */
hConIn = GetStdHandle(STD_INPUT_HANDLE);
hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -1135,14 +1158,15 @@ windows_nhbell(void)
/*ARGSUSED*/
int
windows_nh_poskey(int *x, int *y, int *mod)
windows_nh_poskey(int *x UNUSED, int *y UNUSED, int *mod UNUSED)
{
return '\033';
}
/*ARGSUSED*/
char
windows_yn_function(const char* query, const char* resp, char def)
windows_yn_function(const char* query UNUSED, const char* resp UNUSED,
char def UNUSED)
{
return '\033';
}
@@ -1329,7 +1353,7 @@ file_exists(const char* path)
RESTORE_WARNING_UNREACHABLE_CODE
/*
/*
file_newer returns TRUE if the file at a_path is newer then the file
at b_path. If a_path does not exist, it returns FALSE. If b_path
does not exist, it returns TRUE.

View File

@@ -4,7 +4,7 @@
/*
* WIN32 system functions.
*
*
* Included in both console-based and window-based clients on the windows platform.
*
* Initial Creation: Michael Allison - January 31/93
@@ -49,14 +49,22 @@ extern boolean getreturn_enabled;
int redirect_stdout;
#ifdef WIN32CON
typedef HWND(WINAPI *GETCONSOLEWINDOW)();
typedef HWND(WINAPI *GETCONSOLEWINDOW)(void);
#ifdef WIN32CON
static HWND GetConsoleHandle(void);
static HWND GetConsoleHwnd(void);
#endif
#if !defined(TTY_GRAPHICS)
extern void backsp(void);
#endif
int windows_console_custom_nhgetch(void);
extern void safe_routines(void);
int windows_early_options(const char *window_opt);
unsigned long sys_random_seed(void);
#if 0
static int max_filename(void);
#endif
/* The function pointer nt_kbhit contains a kbhit() equivalent
* which varies depending on which window port is active.
@@ -66,7 +74,7 @@ extern void safe_routines(void);
*/
int def_kbhit(void);
int (*nt_kbhit)() = def_kbhit;
int (*nt_kbhit)(void) = def_kbhit;
#endif /* WIN32CON */
#ifndef WIN32CON
@@ -157,6 +165,7 @@ chdrive(char* str)
}
}
#if 0
static int
max_filename(void)
{
@@ -170,6 +179,7 @@ max_filename(void)
else
return 0;
}
#endif
int
def_kbhit(void)
@@ -208,6 +218,8 @@ extern void mswin_raw_print_flush(void);
extern void mswin_raw_print(const char *);
#endif
DISABLE_WARNING_FORMAT_NONLITERAL
/* fatal error */
/*VARARGS1*/
void error
@@ -237,6 +249,8 @@ VA_DECL(const char *, s)
exit(EXIT_FAILURE);
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
Delay(int ms)
{
@@ -317,7 +331,7 @@ void
interject(int interjection_type)
{
if (interjection_type >= 0 && interjection_type < INTERJECTION_TYPES)
msmsg(interjection_buf[interjection_type]);
msmsg("%s", interjection_buf[interjection_type]);
}
#ifdef RUNTIME_PASTEBUF_SUPPORT
@@ -328,22 +342,23 @@ void port_insert_pastebuf(char *buf)
* to accomplish this.
*/
HGLOBAL hglbCopy;
HGLOBAL hglbCopy;
WCHAR *w, w2[2];
int cc, rc, abytes;
/* int cc; */
int rc, abytes;
LPWSTR lpwstrCopy;
HANDLE hresult;
if (!buf)
return;
cc = strlen(buf);
return;
/* cc = strlen(buf); */
/* last arg=0 means "tell me the size of the buffer that I need" */
rc = MultiByteToWideChar(GetConsoleOutputCP(), 0, buf, -1, w2, 0);
if (!rc) return;
abytes = rc * sizeof(WCHAR);
w = (WCHAR *)alloc(abytes);
w = (WCHAR *)alloc(abytes);
/* Housekeeping need: +free(w) */
rc = MultiByteToWideChar(GetConsoleOutputCP(), 0, buf, -1, w, rc);
@@ -357,18 +372,18 @@ void port_insert_pastebuf(char *buf)
}
/* Housekeeping need: +CloseClipboard(), free(w) */
EmptyClipboard();
EmptyClipboard();
/* allocate global mem obj to hold the text */
hglbCopy = GlobalAlloc(GMEM_MOVEABLE, abytes);
if (hglbCopy == NULL) {
CloseClipboard();
if (hglbCopy == NULL) {
CloseClipboard();
free(w);
return;
}
}
/* Housekeeping need: +GlobalFree(hglbCopy), CloseClipboard(), free(w) */
lpwstrCopy = (LPWSTR)GlobalLock(hglbCopy);
/* Housekeeping need: +GlobalUnlock(hglbCopy), GlobalFree(hglbCopy),
CloseClipboard(), free(w) */
@@ -384,8 +399,8 @@ void port_insert_pastebuf(char *buf)
GlobalFree(hglbCopy); /* only needed if clipboard didn't accept data */
}
/* Housekeeping need: CloseClipboard(), free(w) */
CloseClipboard();
CloseClipboard();
free(w);
return;
}
@@ -566,8 +581,10 @@ WCHAR *
winos_ascii_to_wide_str(const unsigned char * src, WCHAR * dst, size_t dstLength)
{
size_t i = 0;
while(i < dstLength - 1 && src[i] != 0)
dst[i++] = cp437[src[i]];
while(i < dstLength - 1 && src[i] != 0) {
dst[i] = cp437[src[i]];
i++;
}
dst[i] = 0;
return dst;
}
@@ -644,7 +661,8 @@ windows_early_options(const char *window_opt)
return 1;
} else {
raw_printf(
"-%swindows:cursorblink is the only supported option.\n");
"-%s windows:cursorblink is the only supported option.\n",
window_opt);
}
return 0;
}
@@ -690,10 +708,10 @@ sys_random_seed(void)
status = BCryptOpenAlgorithmProvider(&hRa, BCRYPT_RNG_ALGORITHM,
(LPCWSTR) 0, 0);
if (hRa && status == STATUS_SUCCESS) {
if (hRa && status == (NTSTATUS) STATUS_SUCCESS) {
status = BCryptGenRandom(hRa, (PUCHAR) &ourseed,
(ULONG) sizeof ourseed, 0);
if (status == STATUS_SUCCESS) {
if (status == (NTSTATUS) STATUS_SUCCESS) {
BCryptCloseAlgorithmProvider(hRa,0);
has_strong_rngseed = TRUE;
Plan_B = FALSE;
@@ -726,7 +744,7 @@ nt_assert_failed(const char *expression, const char *filepath, int line)
if (IsDebuggerPresent()) {
char message[BUFSIZ];
snprintf(message, sizeof(message),
snprintf(message, sizeof(message),
"nhassert(%s) failed in file '%s' at line %d",
expression, filename, line);
OutputDebugStringA(message);