Module Name: src
Committed By: lukem
Date: Sun Apr 12 13:07:21 UTC 2009
Modified Files:
src/usr.bin/last: last.c want.c
Log Message:
Fix WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare)
To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/last/last.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/last/want.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/last/last.c
diff -u src/usr.bin/last/last.c:1.32 src/usr.bin/last/last.c:1.33
--- src/usr.bin/last/last.c:1.32 Mon Jul 21 14:19:23 2008
+++ src/usr.bin/last/last.c Sun Apr 12 13:07:21 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: last.c,v 1.32 2008/07/21 14:19:23 lukem Exp $ */
+/* $NetBSD: last.c,v 1.33 2009/04/12 13:07:21 lukem Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94";
#endif
-__RCSID("$NetBSD: last.c,v 1.32 2008/07/21 14:19:23 lukem Exp $");
+__RCSID("$NetBSD: last.c,v 1.33 2009/04/12 13:07:21 lukem Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -92,11 +92,11 @@
#define MAXUTMP 1024
typedef struct arg {
- char *name; /* argument */
+ const char *name; /* argument */
#define HOST_TYPE -2
#define TTY_TYPE -3
#define USER_TYPE -4
- int type; /* type of arg */
+ int type; /* type of arg */
struct arg *next; /* linked list pointer */
} ARG;
static ARG *arglist; /* head of linked list */
@@ -115,10 +115,10 @@
int main(int, char *[]);
-static void addarg(int, char *);
+static void addarg(int, const char *);
static TTY *addtty(const char *);
static void hostconv(char *);
-static char *ttyconv(char *);
+static const char *ttyconv(char *);
#ifdef SUPPORT_UTMPX
static void wtmpx(const char *, int, int, int, int);
#endif
@@ -148,7 +148,7 @@
{
int ch;
char *p;
- char *file = NULL;
+ const char *file = NULL;
int namesize = UT_NAMESIZE;
int linesize = UT_LINESIZE;
int hostsize = UT_HOSTSIZE;
@@ -271,7 +271,7 @@
* add an entry to a linked list of arguments
*/
static void
-addarg(int type, char *arg)
+addarg(int type, const char *arg)
{
ARG *cur;
@@ -288,7 +288,7 @@
* add an entry to a linked list of ttys
*/
static TTY *
-addtty(const char *ttyname)
+addtty(const char *tty)
{
TTY *cur;
@@ -296,7 +296,7 @@
err(EXIT_FAILURE, "malloc failure");
cur->next = ttylist;
cur->logout = currentout;
- memmove(cur->tty, ttyname, sizeof(cur->tty));
+ memmove(cur->tty, tty, sizeof(cur->tty));
return (ttylist = cur);
}
@@ -330,7 +330,7 @@
* ttyconv --
* convert tty to correct name.
*/
-static char *
+static const char *
ttyconv(char *arg)
{
char *mval;
Index: src/usr.bin/last/want.c
diff -u src/usr.bin/last/want.c:1.12 src/usr.bin/last/want.c:1.13
--- src/usr.bin/last/want.c:1.12 Mon Dec 29 01:25:04 2008
+++ src/usr.bin/last/want.c Sun Apr 12 13:07:21 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: want.c,v 1.12 2008/12/29 01:25:04 christos Exp $ */
+/* $NetBSD: want.c,v 1.13 2009/04/12 13:07:21 lukem Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -42,11 +42,11 @@
return numeric ? "" : host;
#else
if (numeric) {
- static char buf[512];
- buf[0] = '\0';
- (void)sockaddr_snprintf(buf, sizeof(buf), "%a",
+ static char hbuf[512];
+ hbuf[0] = '\0';
+ (void)sockaddr_snprintf(hbuf, sizeof(hbuf), "%a",
(struct sockaddr *)&ut->ut_ss);
- return buf;
+ return hbuf;
} else
return host;
#endif
@@ -71,14 +71,15 @@
struct stat stb; /* stat of file for sz */
off_t offset;
int wfd;
- char *ct, *crmsg;
+ char *ct;
+ const char *crmsg;
size_t len = sizeof(*buf) * MAXUTMP;
char namebuf[sizeof(bp->ut_name) + 1], *namep;
char linebuf[sizeof(bp->ut_line) + 1], *linep;
char hostbuf[sizeof(bp->ut_host) + 1], *hostp;
- int checkname = namesz > sizeof(bp->ut_name);
- int checkline = linesz > sizeof(bp->ut_line);
- int checkhost = hostsz > sizeof(bp->ut_host);
+ int checkname = namesz > (int)sizeof(bp->ut_name);
+ int checkline = linesz > (int)sizeof(bp->ut_line);
+ int checkhost = hostsz > (int)sizeof(bp->ut_host);
if ((buf = malloc(len)) == NULL)
err(EXIT_FAILURE, "Cannot allocate utmp buffer");
@@ -141,7 +142,7 @@
ssize_t ret, i;
size_t size;
- size = MIN(len, offset);
+ size = MIN((off_t)len, offset);
offset -= size; /* Always a multiple of sizeof(*buf) */
ret = pread(wfd, buf, size, offset);
if (ret < 0) {