Lowering the scope And cleaning up some warnings from static analysis

This commit is contained in:
NHOrus 2017-06-14 22:08:43 +03:00 committed by Eric S. Raymond
parent 7c9a0bfb36
commit 46bb20deb3
6 changed files with 11 additions and 15 deletions

View file

@ -774,11 +774,10 @@ static int quit(FILE *input)
static int read(FILE *input, token_t verb, token_t obj) static int read(FILE *input, token_t verb, token_t obj)
/* Read. Print stuff based on objtxt. Oyster (?) is special case. */ /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
{ {
int i;
int spk = ACTSPK[verb]; int spk = ACTSPK[verb];
if (obj == INTRANSITIVE) { if (obj == INTRANSITIVE) {
obj = 0; 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) if (HERE(i) && OBJTXT[i] != 0 && game.prop[i] >= 0)
obj = obj * NOBJECTS + i; obj = obj * NOBJECTS + i;
} }

View file

@ -82,7 +82,7 @@ extern bool oldstyle, editline, prompt;
#define READ_MODE "rb" #define READ_MODE "rb"
#define WRITE_MODE "wb" #define WRITE_MODE "wb"
extern char* xstrdup(const char*); 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 newspeak(char*);
extern void PSPEAK(vocab_t,int); extern void PSPEAK(vocab_t,int);
extern void RSPEAK(vocab_t); extern void RSPEAK(vocab_t);

View file

@ -197,7 +197,7 @@ void MAPLIN(FILE *OPENED) {
while (!feof(OPENED) && INLINE[1] == '#'); while (!feof(OPENED) && INLINE[1] == '#');
LNLENG = 0; 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]; char val = INLINE[i];
INLINE[i] = ascii_to_advent[(unsigned)val]; 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 * scanned). If we're at the end of the line or encounter an illegal
* character (not a digit, hyphen, or blank), we return 0. */ * character (not a digit, hyphen, or blank), we return 0. */
long DIGIT, GETNUM, SIGN; long GETNUM, SIGN;
if(source != NULL) MAPLIN(source); if(source != NULL) MAPLIN(source);
GETNUM = 0; GETNUM = 0;
@ -235,7 +235,7 @@ long GETNUM(FILE *source) {
} }
while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0)) while (!(LNPOSN > LNLENG || INLINE[LNPOSN] == 0))
{ {
DIGIT=INLINE[LNPOSN]-64; long DIGIT=INLINE[LNPOSN]-64;
if(DIGIT < 0 || DIGIT > 9) if(DIGIT < 0 || DIGIT > 9)
{ {
GETNUM=0; GETNUM=0;

3
main.c
View file

@ -860,10 +860,9 @@ static void listobjects(void)
* get full score. */ * get full score. */
{ {
if (!DARK(game.loc)) { if (!DARK(game.loc)) {
long obj;
++game.abbrev[game.loc]; ++game.abbrev[game.loc];
for (int i=game.atloc[game.loc]; i != 0; i=game.link[i]) { 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 > NOBJECTS)obj=obj-NOBJECTS;
if (obj == STEPS && TOTING(NUGGET)) if (obj == STEPS && TOTING(NUGGET))
continue; continue;

7
misc.c
View file

@ -541,7 +541,6 @@ void BUG(long num)
bool MAPLIN(FILE *fp) bool MAPLIN(FILE *fp)
{ {
long i, val;
bool eof; bool eof;
/* Read a line of input, from the specified input source. /* Read a line of input, from the specified input source.
@ -577,7 +576,7 @@ bool MAPLIN(FILE *fp)
if (!eof) { if (!eof) {
strncpy(rawbuf, cp, sizeof(rawbuf)-1); strncpy(rawbuf, cp, sizeof(rawbuf)-1);
linenoiseHistoryAdd(rawbuf); linenoiseHistoryAdd(rawbuf);
strncat(rawbuf, "\n", sizeof(rawbuf)-1); strncat(rawbuf, "\n", sizeof(rawbuf) - strlen(rawbuf) - 1);
linenoiseFree(cp); linenoiseFree(cp);
} }
} }
@ -624,8 +623,8 @@ bool MAPLIN(FILE *fp)
* and is not changed thereafter unless the routines on this page choose * and is not changed thereafter unless the routines on this page choose
* to do so. */ * to do so. */
LNLENG=0; LNLENG=0;
for (i=1; i<=(long)sizeof(INLINE) && INLINE[i]!=0; i++) { for (long i=1; i<=(long)sizeof(INLINE) && INLINE[i]!=0; i++) {
val=INLINE[i]; long val=INLINE[i];
INLINE[i]=ascii_to_advent[val]; INLINE[i]=ascii_to_advent[val];
if (INLINE[i] != 0) if (INLINE[i] != 0)
LNLENG=i; LNLENG=i;

View file

@ -33,7 +33,6 @@ int saveresume(FILE *input, bool resume)
{ {
long i, k; long i, k;
FILE *fp = NULL; FILE *fp = NULL;
char *name;
if (!resume) { if (!resume) {
/* Suspend. Offer to save things in a file, but charging /* Suspend. Offer to save things in a file, but charging
@ -53,7 +52,7 @@ int saveresume(FILE *input, bool resume)
} }
while (fp == NULL) { while (fp == NULL) {
name = linenoise("\nFile name: "); char* name = linenoise("\nFile name: ");
if (name == NULL) if (name == NULL)
return GO_TOP; return GO_TOP;
fp = fopen(name,(resume ? READ_MODE : WRITE_MODE)); fp = fopen(name,(resume ? READ_MODE : WRITE_MODE));