From 46bb20deb3fa90a2675c89e254560f401f666493 Mon Sep 17 00:00:00 2001 From: NHOrus Date: Wed, 14 Jun 2017 22:08:43 +0300 Subject: [PATCH] Lowering the scope And cleaning up some warnings from static analysis --- actions.c | 3 +-- advent.h | 2 +- dungeon.c | 6 +++--- main.c | 3 +-- misc.c | 7 +++---- saveresume.c | 5 ++--- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/actions.c b/actions.c index 5197250..cc2f66c 100644 --- a/actions.c +++ b/actions.c @@ -774,11 +774,10 @@ static int quit(FILE *input) static int read(FILE *input, token_t verb, token_t obj) /* Read. Print stuff based on objtxt. Oyster (?) is special case. */ { - int i; int spk = ACTSPK[verb]; if (obj == INTRANSITIVE) { obj = 0; - for (i=1; i<=NOBJECTS; i++) { + for (int i=1; i<=NOBJECTS; i++) { if (HERE(i) && OBJTXT[i] != 0 && game.prop[i] >= 0) obj = obj * NOBJECTS + i; } diff --git a/advent.h b/advent.h index 4717fe7..93681a6 100644 --- a/advent.h +++ b/advent.h @@ -82,7 +82,7 @@ extern bool oldstyle, editline, prompt; #define READ_MODE "rb" #define WRITE_MODE "wb" extern char* xstrdup(const char*); -extern void packed_to_token(long, char token[6]); +extern void packed_to_token(long, char token[]); extern void newspeak(char*); extern void PSPEAK(vocab_t,int); extern void RSPEAK(vocab_t); diff --git a/dungeon.c b/dungeon.c index 1f56f84..b22997d 100644 --- a/dungeon.c +++ b/dungeon.c @@ -197,7 +197,7 @@ void MAPLIN(FILE *OPENED) { while (!feof(OPENED) && INLINE[1] == '#'); LNLENG = 0; - for (size_t i = 1; i <= sizeof(INLINE) && INLINE[i] != 0; ++i) + for (size_t i = 1; i < sizeof(INLINE) && INLINE[i] != 0; ++i) { char val = INLINE[i]; INLINE[i] = ascii_to_advent[(unsigned)val]; @@ -214,7 +214,7 @@ long GETNUM(FILE *source) { * scanned). If we're at the end of the line or encounter an illegal * character (not a digit, hyphen, or blank), we return 0. */ - long DIGIT, GETNUM, SIGN; + long GETNUM, SIGN; if(source != NULL) MAPLIN(source); GETNUM = 0; @@ -235,7 +235,7 @@ long GETNUM(FILE *source) { } while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0)) { - DIGIT=INLINE[LNPOSN]-64; + long DIGIT=INLINE[LNPOSN]-64; if(DIGIT < 0 || DIGIT > 9) { GETNUM=0; diff --git a/main.c b/main.c index 6ba8897..ecc9ca0 100644 --- a/main.c +++ b/main.c @@ -860,10 +860,9 @@ static void listobjects(void) * get full score. */ { if (!DARK(game.loc)) { - long obj; ++game.abbrev[game.loc]; for (int i=game.atloc[game.loc]; i != 0; i=game.link[i]) { - obj=i; + long obj=i; if (obj > NOBJECTS)obj=obj-NOBJECTS; if (obj == STEPS && TOTING(NUGGET)) continue; diff --git a/misc.c b/misc.c index 6ca1f87..a59ed5f 100644 --- a/misc.c +++ b/misc.c @@ -541,7 +541,6 @@ void BUG(long num) bool MAPLIN(FILE *fp) { - long i, val; bool eof; /* Read a line of input, from the specified input source. @@ -577,7 +576,7 @@ bool MAPLIN(FILE *fp) if (!eof) { strncpy(rawbuf, cp, sizeof(rawbuf)-1); linenoiseHistoryAdd(rawbuf); - strncat(rawbuf, "\n", sizeof(rawbuf)-1); + strncat(rawbuf, "\n", sizeof(rawbuf) - strlen(rawbuf) - 1); linenoiseFree(cp); } } @@ -624,8 +623,8 @@ bool MAPLIN(FILE *fp) * and is not changed thereafter unless the routines on this page choose * to do so. */ LNLENG=0; - for (i=1; i<=(long)sizeof(INLINE) && INLINE[i]!=0; i++) { - val=INLINE[i]; + for (long i=1; i<=(long)sizeof(INLINE) && INLINE[i]!=0; i++) { + long val=INLINE[i]; INLINE[i]=ascii_to_advent[val]; if (INLINE[i] != 0) LNLENG=i; diff --git a/saveresume.c b/saveresume.c index af94c4a..284b8f0 100644 --- a/saveresume.c +++ b/saveresume.c @@ -33,8 +33,7 @@ int saveresume(FILE *input, bool resume) { long i, k; FILE *fp = NULL; - char *name; - + if (!resume) { /* Suspend. Offer to save things in a file, but charging * some points (so can't win by using saved games to retry @@ -53,7 +52,7 @@ int saveresume(FILE *input, bool resume) } while (fp == NULL) { - name = linenoise("\nFile name: "); + char* name = linenoise("\nFile name: "); if (name == NULL) return GO_TOP; fp = fopen(name,(resume ? READ_MODE : WRITE_MODE)); -- 2.31.1