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
+17 -18
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