From 2de068a98aaeb8a1e9e8f2e719b5ff6ebf858b44 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 26 Jun 2019 19:37:00 -0700 Subject: GLK: ALAN3: Further warning fixes --- engines/glk/alan3/alan3.cpp | 4 ++++ engines/glk/alan3/args.cpp | 4 ++-- engines/glk/alan3/container.cpp | 2 +- engines/glk/alan3/debug.cpp | 32 ++++++++++++++-------------- engines/glk/alan3/decode.cpp | 2 +- engines/glk/alan3/exe.cpp | 46 ++++++++++++++++++++--------------------- engines/glk/alan3/glkstart.cpp | 2 +- engines/glk/alan3/glkstart.h | 6 +++--- engines/glk/alan3/instance.cpp | 4 ++-- engines/glk/alan3/inter.cpp | 14 ++++++------- engines/glk/alan3/main.cpp | 6 +----- engines/glk/alan3/output.cpp | 26 ++++++++++++----------- engines/glk/alan3/parse.cpp | 4 ++-- engines/glk/alan3/readline.cpp | 4 +++- engines/glk/alan3/reverse.cpp | 12 +++++------ engines/glk/alan3/scan.cpp | 2 +- engines/glk/alan3/sysdep.cpp | 4 ++-- engines/glk/alan3/syserr.cpp | 18 ++++++++-------- engines/glk/alan3/syserr.h | 8 +++---- engines/glk/alan3/utils.cpp | 4 ++-- engines/glk/alan3/utils.h | 4 ++-- 21 files changed, 106 insertions(+), 102 deletions(-) (limited to 'engines/glk/alan3') diff --git a/engines/glk/alan3/alan3.cpp b/engines/glk/alan3/alan3.cpp index d5a062b76a..c7c4c6c48e 100644 --- a/engines/glk/alan3/alan3.cpp +++ b/engines/glk/alan3/alan3.cpp @@ -25,6 +25,7 @@ #include "glk/alan3/main.h" #include "glk/alan3/glkio.h" #include "glk/alan3/options.h" +#include "glk/alan3/syserr.h" #include "common/system.h" #include "common/config-manager.h" #include "common/translation.h" @@ -58,6 +59,9 @@ Alan3::Alan3(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, g logOption = false; statusLineOption = true; regressionTestOption = false; + + // syserr + setSyserrHandler(nullptr); } void Alan3::runGame() { diff --git a/engines/glk/alan3/args.cpp b/engines/glk/alan3/args.cpp index 7a020cd1f0..12cf1e885c 100644 --- a/engines/glk/alan3/args.cpp +++ b/engines/glk/alan3/args.cpp @@ -37,7 +37,7 @@ char *adventureName; /* The name of the game */ char *adventureFileName; /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ - +#if 0 /*======================================================================*/ char *gameName(char *fullPathName) { char *foundGameName = ""; @@ -148,7 +148,7 @@ static void switches(int argc, char *argv[]) } } } - +#endif /*----------------------------------------------------------------------*/ bool differentInterpreterName(char *string) { diff --git a/engines/glk/alan3/container.cpp b/engines/glk/alan3/container.cpp index b9508f55db..365455c0ce 100644 --- a/engines/glk/alan3/container.cpp +++ b/engines/glk/alan3/container.cpp @@ -101,7 +101,7 @@ bool passesContainerLimits(Aint theContainer, Aint theAddedInstance) { if (containers[props].limits != 0) { /* Any limits at all? */ for (limit = (LimitEntry *) pointerTo(containers[props].limits); !isEndOfArray(limit); limit++) - if (limit->atr == 1-I_COUNT) { /* TODO This is actually some encoding of the attribute number, right? */ + if ((int)limit->atr == 1-I_COUNT) { /* TODO This is actually some encoding of the attribute number, right? */ if (countInContainer(theContainer) >= (int)limit->val) { interpret(limit->stms); return(FALSE); diff --git a/engines/glk/alan3/debug.cpp b/engines/glk/alan3/debug.cpp index c196897531..25de184a7b 100644 --- a/engines/glk/alan3/debug.cpp +++ b/engines/glk/alan3/debug.cpp @@ -118,7 +118,7 @@ static void sayInstanceNumberAndName(int ins) { /*----------------------------------------------------------------------*/ -static void sayLocationOfInstance(int ins, char *prefix) { +static void sayLocationOfInstance(int ins, const char *prefix) { if (admin[ins].location == 0) return; else { @@ -598,7 +598,7 @@ static void setBreakpoint(int file, int line) { int lineIndex = findSourceLineIndex((SourceLineEntry *)pointerTo(header->sourceLineTable), file, line); SourceLineEntry *entry = (SourceLineEntry *)pointerTo(header->sourceLineTable); char leadingText[100] = "Breakpoint"; - if (entry[lineIndex].file == EOD) { + if (entry[lineIndex].file == (Aint)EOD) { printf("Line %d not available\n", line); } else { if (entry[lineIndex].line != line) @@ -684,13 +684,13 @@ void restoreInfo(void) #define TRACE_STACK_COMMAND 't' typedef struct DebugParseEntry { - char *command; - char *parameter; + const char *command; + const char *parameter; char code; - char *helpText; + const char *helpText; } DebugParseEntry; -static DebugParseEntry commandEntries[] = { +static const DebugParseEntry commandEntries[] = { {"help", "", HELP_COMMAND, "this help"}, {"?", "", HELP_COMMAND, "d:o"}, {"break", "[[file:]n]", BREAK_COMMAND, "set breakpoint at source line [n] (optionally in [file])"}, @@ -708,16 +708,16 @@ static DebugParseEntry commandEntries[] = { {"exit", "", EXIT_COMMAND, "exit to game, enter 'debug' to get back"}, {"x", "", EXIT_COMMAND, "d:o"}, {"quit", "", QUIT_COMMAND, "quit game"}, - {NULL, NULL} + {NULL, NULL, '\0', NULL} }; -static DebugParseEntry traceSubcommand[] = { +static const DebugParseEntry traceSubcommand[] = { {"source", "", TRACE_SOURCE_COMMAND, ""}, {"section", "", TRACE_SECTION_COMMAND, ""}, {"instructions", "", TRACE_INSTRUCTION_COMMAND, ""}, {"pushs", "", TRACE_PUSH_COMMAND, ""}, {"stacks", "", TRACE_STACK_COMMAND, ""}, - {NULL, NULL} + {NULL, NULL, '\0', NULL} }; @@ -733,7 +733,7 @@ static char *spaces(int length) { /*----------------------------------------------------------------------*/ -static char *padding(DebugParseEntry *entry, int maxLength) { +static char *padding(const DebugParseEntry *entry, int maxLength) { return spaces(maxLength-strlen(entry->command)-strlen(entry->parameter)); } @@ -743,7 +743,7 @@ static void handleHelpCommand() { if (!regressionTestOption) output(alan.longHeader); - DebugParseEntry *entry = commandEntries; + const DebugParseEntry *entry = commandEntries; int maxLength = 0; for (entry = commandEntries; entry->command != NULL; entry++) { @@ -761,7 +761,7 @@ static void handleHelpCommand() { /*----------------------------------------------------------------------*/ -static DebugParseEntry *findEntry(char *command, DebugParseEntry *entry) { +static const DebugParseEntry *findEntry(char *command, const DebugParseEntry *entry) { while (entry->command != NULL) { if (strncasecmp(command, entry->command, strlen(command)) == 0) return entry; @@ -773,7 +773,7 @@ static DebugParseEntry *findEntry(char *command, DebugParseEntry *entry) { /*----------------------------------------------------------------------*/ static char parseDebugCommand(char *command) { - DebugParseEntry *entry = findEntry(command, commandEntries); + const DebugParseEntry *entry = findEntry(command, commandEntries); if (entry != NULL) { if (strlen(command) < strlen(entry->command)) { /* See if there are any more partial matches */ @@ -812,7 +812,7 @@ static void readCommand(char buf[]) { /*----------------------------------------------------------------------*/ static void displaySourceLocation(int line, int fileNumber) { - char *cause; + const char *cause; if (anyOutput) newline(); if (breakpointIndex(fileNumber, line) != -1) cause = "Breakpoint hit at"; @@ -871,7 +871,7 @@ static void toggleStackTrace() { /*----------------------------------------------------------------------*/ static int parseTraceCommand() { char *subcommand = strtok(NULL, ""); - DebugParseEntry *entry; + const DebugParseEntry *entry; if (subcommand == 0) return UNKNOWN_COMMAND; else { @@ -889,7 +889,7 @@ static int parseTraceCommand() { /*----------------------------------------------------------------------*/ -static char *printTraceState(bool state) { +static const char *printTraceState(bool state) { if (state) return "on - Traces"; else diff --git a/engines/glk/alan3/decode.cpp b/engines/glk/alan3/decode.cpp index 4fe2af7df1..41afbddca6 100644 --- a/engines/glk/alan3/decode.cpp +++ b/engines/glk/alan3/decode.cpp @@ -48,7 +48,7 @@ static int inputBit(void) if (!bitsToGo) { /* No, so get more */ decodeBuffer = (textFile->pos() >= textFile->size()) ? EOD : textFile->readByte(); - if (decodeBuffer == EOD) { + if (decodeBuffer == (int)EOD) { garbageBits++; if (garbageBits > VALUEBITS-2) syserr("Error in encoded data file."); diff --git a/engines/glk/alan3/exe.cpp b/engines/glk/alan3/exe.cpp index 7f0fe2b687..f37cc2f661 100644 --- a/engines/glk/alan3/exe.cpp +++ b/engines/glk/alan3/exe.cpp @@ -340,8 +340,10 @@ void schedule(Aword event, Aword where, Aword after) cancelEvent(event); /* Check for overflow */ - if (eventQueue == NULL || eventQueueTop == eventQueueSize) + if (eventQueue == nullptr || eventQueueTop == eventQueueSize) { increaseEventQueue(); + assert(eventQueue); + } /* Bubble this event down */ for (i = eventQueueTop; i >= 1 && eventQueue[i-1].after <= (int)after; i--) { @@ -713,35 +715,33 @@ bool streq(char a[], char b[]) /*======================================================================*/ void startTranscript(void) { - if (logFile != NULL) - return; - - Common::String filename = g_vm->getTargetName() + ".log"; - - uint fileUsage = transcriptOption ? fileusage_Transcript : fileusage_InputRecord; - frefid_t logFileRef = g_vm->glk_fileref_create_by_name(fileUsage, filename.c_str(), 0); - logFile = g_vm->glk_stream_open_file(logFileRef, filemode_Write, 0); - - if (logFile == NULL) { - transcriptOption = FALSE; - logOption = FALSE; - } else { - transcriptOption = TRUE; + if (logFile == NULL) { + Common::String filename = g_vm->getTargetName() + ".log"; + + uint fileUsage = transcriptOption ? fileusage_Transcript : fileusage_InputRecord; + frefid_t logFileRef = g_vm->glk_fileref_create_by_name(fileUsage, filename.c_str(), 0); + logFile = g_vm->glk_stream_open_file(logFileRef, filemode_Write, 0); + + if (logFile == NULL) { + transcriptOption = FALSE; + logOption = FALSE; + } else { + transcriptOption = TRUE; + } } } /*======================================================================*/ void stopTranscript(void) { - if (logFile == NULL) - return; - - if (transcriptOption|| logOption) - delete logFile; + if (logFile != NULL) { + if (transcriptOption|| logOption) + delete logFile; - logFile = NULL; - transcriptOption = FALSE; - logOption = FALSE; + logFile = NULL; + transcriptOption = FALSE; + logOption = FALSE; + } } } // End of namespace Alan3 diff --git a/engines/glk/alan3/glkstart.cpp b/engines/glk/alan3/glkstart.cpp index 0c54cfd447..da20f0fd66 100644 --- a/engines/glk/alan3/glkstart.cpp +++ b/engines/glk/alan3/glkstart.cpp @@ -42,7 +42,7 @@ namespace Glk { namespace Alan3 { -glkunix_argumentlist_t glkunix_arguments[] = { +const glkunix_argumentlist_t glkunix_arguments[] = { { "-l", glkunix_arg_NoValue, "-l: log player command and game output" }, { "-c", glkunix_arg_NoValue, "-c: log player commands to a file" }, { "-n", glkunix_arg_NoValue, "-n: no status line" }, diff --git a/engines/glk/alan3/glkstart.h b/engines/glk/alan3/glkstart.h index 4420bea2f9..2bc2e9c9dc 100644 --- a/engines/glk/alan3/glkstart.h +++ b/engines/glk/alan3/glkstart.h @@ -60,9 +60,9 @@ namespace Alan3 { #define glkunix_arg_NumberValue (4) struct glkunix_argumentlist_t { - char *name; + const char *name; int argtype; - char *desc; + const char *desc; }; struct glkunix_startup_t { @@ -71,7 +71,7 @@ struct glkunix_startup_t { }; /* The list of command-line arguments; this should be defined in your code. */ -extern glkunix_argumentlist_t glkunix_arguments[]; +extern const glkunix_argumentlist_t glkunix_arguments[]; /* The external function; this should be defined in your code. */ extern int glkunix_startup_code(glkunix_startup_t *data); diff --git a/engines/glk/alan3/instance.cpp b/engines/glk/alan3/instance.cpp index a761b5603d..d2670f3b46 100644 --- a/engines/glk/alan3/instance.cpp +++ b/engines/glk/alan3/instance.cpp @@ -202,7 +202,7 @@ Set *getInstanceSetAttribute(int instance, int attribute) /*----------------------------------------------------------------------*/ -static void verifyInstance(int instance, char *action) { +static void verifyInstance(int instance, const char *action) { char message[200]; if (instance == 0) { @@ -1053,7 +1053,7 @@ static void locateActor(Aint movingActor, Aint whr) /*----------------------------------------------------------------------*/ -static void traceExtract(int instance, int containerId, char *what) { +static void traceExtract(int instance, int containerId, const char *what) { if (traceSectionOption) { printf("\ncode != EOS) + while (!isEndOfArray(elms) && (Aword)elms->code != EOS) elms++; if (isEndOfArray(elms)) /* No match for EOS! */ return NULL; diff --git a/engines/glk/alan3/readline.cpp b/engines/glk/alan3/readline.cpp index 552e3b5627..fa965bbd76 100644 --- a/engines/glk/alan3/readline.cpp +++ b/engines/glk/alan3/readline.cpp @@ -147,7 +147,9 @@ bool readline(char buffer[]) } break; #endif - } + default: + break; + } } while (event.type != evtype_LineInput); if (buffer[0] == '@') { buffer[event.val1] = 0; diff --git a/engines/glk/alan3/reverse.cpp b/engines/glk/alan3/reverse.cpp index d31e7c3f2f..2a0cd427ad 100644 --- a/engines/glk/alan3/reverse.cpp +++ b/engines/glk/alan3/reverse.cpp @@ -78,7 +78,7 @@ Aword reversed(Aword w) /* IN - The ACODE word to swap bytes of */ #else Aword s; /* The swapped ACODE word */ char *wp, *sp; - int i; + uint i; wp = (char *) &w; sp = (char *) &s; @@ -109,7 +109,7 @@ static void reverseTable(Aword adr, int elementSize) Aword *e = &memory[adr]; uint i; - if (elementSize < sizeof(Aword) || elementSize % sizeof(Aword) != 0) + if (elementSize < (int)sizeof(Aword) || elementSize % (int)sizeof(Aword) != 0) syserr("***Wrong size in 'reverseTable()' ***"); if (adr == 0) return; @@ -351,7 +351,7 @@ static void reverseElms(Aword adr) if (!isEndOfArray(e)) { reverseTable(adr, sizeof(ElementEntry)); while (!isEndOfArray(e)) { - if (e->code == EOS) reverseRestrictions(e->next); + if ((uint)e->code == EOS) reverseRestrictions(e->next); else reverseElms(e->next); e++; } @@ -520,7 +520,7 @@ static void reverseSetInitTable(Aaddr adr) /*----------------------------------------------------------------------*/ static void reversePreAlpha5Header(Pre3_0alpha5Header *hdr) { - int i; + uint i; /* Reverse all words in the header except the tag */ for (i = 1; i < sizeof(*hdr)/sizeof(Aword); i++) @@ -561,7 +561,7 @@ static void reversePreAlpha5() { /*----------------------------------------------------------------------*/ static void reversePreBeta2Header(Pre3_0beta2Header *hdr) { - int i; + uint i; /* Reverse all words in the header except the tag */ for (i = 1; i < sizeof(*hdr)/sizeof(Aword); i++) @@ -602,7 +602,7 @@ static void reversePreBeta2() { /*======================================================================*/ void reverseHdr(ACodeHeader *hdr) { - int i; + uint i; /* Reverse all words in the header except the tag and the version marking */ for (i = 1; i < sizeof(*hdr)/sizeof(Aword); i++) diff --git a/engines/glk/alan3/scan.cpp b/engines/glk/alan3/scan.cpp index 4f3855abc8..64c0e6234c 100644 --- a/engines/glk/alan3/scan.cpp +++ b/engines/glk/alan3/scan.cpp @@ -78,7 +78,7 @@ static void unknown(char tok[]) { static int number(char tok[]) { int i; - sscanf(tok, "%d", &i); + (void)sscanf(tok, "%d", &i); return i; } diff --git a/engines/glk/alan3/sysdep.cpp b/engines/glk/alan3/sysdep.cpp index 7e9dc48ce9..6b663938d7 100644 --- a/engines/glk/alan3/sysdep.cpp +++ b/engines/glk/alan3/sysdep.cpp @@ -140,7 +140,7 @@ static const byte upperCaseCharacters[] = int isSpace(unsigned int c) /* IN - Native character to test */ { - return (c != '\0' && strchr((char *)spaceCharacters, c) != 0); + return (c != '\0' && strchr((const char *)spaceCharacters, c) != 0); } @@ -471,7 +471,7 @@ int littleEndian() { /*======================================================================*/ char *baseNameStart(char *fullPathName) { - static char *delimiters = "\\>]/:"; + const char *delimiters = "\\>]/:"; int i; for (i = strlen(fullPathName)-1; i > 0; i--) diff --git a/engines/glk/alan3/syserr.cpp b/engines/glk/alan3/syserr.cpp index 2fceba6059..9ebd397380 100644 --- a/engines/glk/alan3/syserr.cpp +++ b/engines/glk/alan3/syserr.cpp @@ -30,10 +30,10 @@ namespace Glk { namespace Alan3 { -static void (*handler)(char *) = NULL; +static void (*handler)(const char *); /*----------------------------------------------------------------------*/ -static void runtimeError(char *errorClassification, char *errorDescription, char *blurb) { +static void runtimeError(const char *errorClassification, const char *errorDescription, const char *blurb) { output("$n$nAs you enter the twilight zone of Adventures, you stumble \ and fall to your knees. In front of you, you can vaguely see the outlines \ of an Adventure that never was.$n$n"); @@ -54,7 +54,7 @@ of an Adventure that never was.$n$n"); /*======================================================================*/ -void setSyserrHandler(void (*f)(char *)) +void setSyserrHandler(void (*f)(const char *)) { handler = f; } @@ -62,11 +62,11 @@ void setSyserrHandler(void (*f)(char *)) /*======================================================================*/ // TODO Make syserr() use ... as printf() -void syserr(char *description) +void syserr(const char *description) { lin = 0; if (handler == NULL) { - char *blurb = ""; /*======================================================================*/ -void apperr(char *description) +void apperr(const char *description) { if (handler == NULL) { - char *blurb = "