save and restore lint cleanup (trunk only)

Fix a couple of signed vs unsigned and unused paramater warnings
that pointed to actual bugs.  uid values were being handled as int, even
though "modern" systems use type uid_t which could be bigger and is almost
certainly unsigned.  There haven't been any reports of nethack falsely
claiming that the wrong user is trying to restore, so in practice this
hasn't mattered, but switch from int to unsigned long to make the chance
of problems be even smaller.

     The code to save message history was ignoring the 'mode' argument so
would have attepted to write even when asked to free memory instead.  It
isn't currently called by freedynamicdata() so the problem was theoretical
rather than real.

     The 'UNUSED' macro is inadequate to handle parameters which are used
by some conditional configurations and unused by others, so there are
still several warnings about unused parameters from save.c and restore.c.
This commit is contained in:
nethack.rankin
2012-01-18 02:36:50 +00:00
parent c0743f478a
commit 84c9b09440
3 changed files with 22 additions and 22 deletions

View File

@@ -891,7 +891,7 @@ long ttl;
boolean
expire_gas_cloud(p1, p2)
genericptr_t p1;
genericptr_t p2; /* unused here */
genericptr_t p2 UNUSED;
{
NhRegion *reg;
int damage;

View File

@@ -523,10 +523,10 @@ unsigned int *stuckid, *steedid; /* STEED */
#endif
struct obj *otmp, *tmp_bc;
char timebuf[15];
int uid;
unsigned long uid;
mread(fd, (genericptr_t) &uid, sizeof uid);
if (uid != getuid()) { /* strange ... */
if (uid != (unsigned long)getuid()) { /* strange ... */
/* for wizard mode, issue a reminder; for others, treat it
as an attempt to cheat and refuse to restore this file */
pline("Saved game was not yours.");
@@ -701,7 +701,7 @@ STATIC_OVL int
restlevelfile(fd, ltmp)
register int fd;
xchar ltmp;
#if defined(macintosh) && (defined(__SC__) || defined(__MRC__))
#if defined(macintosh) && (defined(__SC__) || defined(__MRC__)) && !defined(MFLOPPY)
# pragma unused(fd)
#endif
{
@@ -901,6 +901,7 @@ register int fd;
return(1);
}
/*ARGSUSED*/
STATIC_OVL void
rest_levl(fd, rlecomp)
int fd;

View File

@@ -302,11 +302,12 @@ STATIC_OVL void
savegamestate(fd, mode)
register int fd, mode;
{
int uid;
unsigned long uid;
#ifdef MFLOPPY
count_only = (mode & COUNT_SAVE);
#endif
uid = getuid();
uid = (unsigned long)getuid();
bwrite(fd, (genericptr_t) &uid, sizeof uid);
bwrite(fd, (genericptr_t) &context, sizeof(struct context_info));
bwrite(fd, (genericptr_t) &flags, sizeof(struct flag));
@@ -725,9 +726,9 @@ register unsigned num;
{
/* lint wants the 3rd arg of write to be an int; lint -p an unsigned */
#if defined(BSD) || defined(ULTRIX) || defined(WIN32) || defined(_MSC_VER)
failed = (write(fd, loc, (int)num) != (int)num);
failed = ((long)write(fd, loc, (int)num) != (long)num);
#else /* e.g. SYSV, __TURBOC__ */
failed = (write(fd, loc, num) != num);
failed = ((long)write(fd, loc, num) != (long)num);
#endif
}
@@ -1190,33 +1191,31 @@ int fd;
STATIC_OVL void
save_msghistory(fd, mode)
register int fd, mode;
int fd, mode;
{
char *msg, buf[BUFSZ];
int msgcount = 0, msglen = 0;
char *msg;
int msgcount = 0, msglen;
int minusone = -1;
boolean init = TRUE;
/* Ask window port for each message in sequence */
while ((msg = getmsghistory(init)) != 0) {
if (perform_bwrite(mode)) {
/* ask window port for each message in sequence */
while ((msg = getmsghistory(init)) != 0) {
init = FALSE;
msglen = strlen(msg);
if (msglen < (BUFSZ-1))
Strcpy(buf, msg);
else {
/* impossible */
(void)strncpy(buf, msg, (BUFSZ - 1));
buf[BUFSZ-1] = '\0';
msglen = strlen(buf);
}
/* sanity: truncate if necessary (shouldn't happen);
no need to modify msg[] since terminator isn't written */
if (msglen > BUFSZ - 1) msglen = BUFSZ - 1;
bwrite(fd, (genericptr_t)&msglen, sizeof(msglen));
bwrite(fd, (genericptr_t)msg, msglen);
++msgcount;
}
bwrite(fd, (genericptr_t) &minusone, sizeof(int));
}
bwrite(fd, (genericptr_t) &minusone, sizeof(int));
#ifdef DEBUG_MSGCOUNT
pline("Stored %d messages into savefile.", msgcount);
#endif
/* note: we don't attempt to handle release_data() here */
}
void