Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/man WARNS=6
details: https://anonhg.NetBSD.org/src/rev/847e366a5db8
branches: trunk
changeset: 788708:847e366a5db8
user: christos <christos%NetBSD.org@localhost>
date: Thu Jul 18 15:39:08 2013 +0000
description:
WARNS=6
- fix cast qual issues
- don't use snprintf on a user-provided buffer
diffstat:
usr.bin/man/Makefile | 4 ++--
usr.bin/man/man.c | 51 +++++++++++++++++++++++++++++++++++----------------
usr.bin/man/manconf.c | 8 ++++----
3 files changed, 41 insertions(+), 22 deletions(-)
diffs (212 lines):
diff -r 1643c4055158 -r 847e366a5db8 usr.bin/man/Makefile
--- a/usr.bin/man/Makefile Thu Jul 18 15:31:49 2013 +0000
+++ b/usr.bin/man/Makefile Thu Jul 18 15:39:08 2013 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.11 2009/04/14 22:15:23 lukem Exp $
+# $NetBSD: Makefile,v 1.12 2013/07/18 15:39:08 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
-WARNS?= 2 # XXX -Wcast-qual issues
+WARNS?= 6
PROG= man
SRCS= man.c manconf.c
diff -r 1643c4055158 -r 847e366a5db8 usr.bin/man/man.c
--- a/usr.bin/man/man.c Thu Jul 18 15:31:49 2013 +0000
+++ b/usr.bin/man/man.c Thu Jul 18 15:39:08 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: man.c,v 1.47 2013/07/18 04:05:32 uwe Exp $ */
+/* $NetBSD: man.c,v 1.48 2013/07/18 15:39:08 christos Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)man.c 8.17 (Berkeley) 1/31/95";
#else
-__RCSID("$NetBSD: man.c,v 1.47 2013/07/18 04:05:32 uwe Exp $");
+__RCSID("$NetBSD: man.c,v 1.48 2013/07/18 15:39:08 christos Exp $");
#endif
#endif /* not lint */
@@ -114,7 +114,7 @@
static const char *check_pager(const char *);
static int cleanup(void);
static void how(char *);
-static void jump(char **, char *, char *);
+static void jump(char **, const char *, const char *);
static int manual(char *, struct manstate *, glob_t *);
static void onsig(int);
static void usage(void) __attribute__((__noreturn__));
@@ -122,13 +122,15 @@
static const char *getclass(const char *);
static void printmanpath(struct manstate *);
+static char EMPTY[1];
+
/*
* main function
*/
int
main(int argc, char **argv)
{
- static struct manstate m = { 0 }; /* init to zero */
+ static struct manstate m;
int ch, abs_section, found;
ENTRY *esubd, *epath;
char *p, **ap, *cmd;
@@ -464,6 +466,21 @@
exit(cleanup());
}
+static void
+fixstring(char *buf, size_t len, const char *fmt, const char *str)
+{
+ const char *ptr = strstr(fmt, "%s");
+ size_t l;
+ if (ptr == NULL) {
+ strlcpy(buf, fmt, len);
+ return;
+ }
+ l = (size_t)(ptr - fmt) + 1;
+ strlcpy(buf, fmt, MIN(l, len));
+ strlcat(buf, str, len);
+ strlcat(buf, ptr + 2, len);
+}
+
static int
manual_find_buildkeyword(char *escpage, const char *fmt,
struct manstate *mp, glob_t *pg, size_t cnt)
@@ -483,7 +500,7 @@
continue;
*p = '\0';
- (void)snprintf(buf, sizeof(buf), fmt, escpage, suffix->s);
+ fixstring(buf, sizeof(buf), fmt, escpage);
if (!fnmatch(buf, pg->gl_pathv[cnt], 0)) {
if (!mp->where)
build_page(p + 1, &pg->gl_pathv[cnt], mp);
@@ -570,14 +587,14 @@
if (!mp->all) {
/* Delete any other matches. */
while (++cnt< pg->gl_pathc)
- pg->gl_pathv[cnt] = "";
+ pg->gl_pathv[cnt] = EMPTY;
break;
}
continue;
}
/* It's not a man page, forget about it. */
- pg->gl_pathv[cnt] = "";
+ pg->gl_pathv[cnt] = EMPTY;
}
notfound:
@@ -626,7 +643,7 @@
if (mp->pathsearch) {
p = strstr(pg->gl_pathv[cnt], mp->pathsearch);
if (!p || strchr(p, '/') == NULL) {
- pg->gl_pathv[cnt] = ""; /* zap! */
+ pg->gl_pathv[cnt] = EMPTY; /* zap! */
continue;
}
}
@@ -665,14 +682,14 @@
if (!mp->all) {
/* Delete any other matches. */
while (++cnt< pg->gl_pathc)
- pg->gl_pathv[cnt] = "";
+ pg->gl_pathv[cnt] = EMPTY;
break;
}
continue;
}
/* It's not a man page, forget about it. */
- pg->gl_pathv[cnt] = "";
+ pg->gl_pathv[cnt] = EMPTY;
}
if (anyfound && !mp->all)
@@ -700,7 +717,8 @@
build_page(char *fmt, char **pathp, struct manstate *mp)
{
static int warned;
- int olddir, fd, n, tmpdirlen;
+ int olddir, fd, n;
+ size_t tmpdirlen;
char *p, *b;
char buf[MAXPATHLEN], cmd[MAXPATHLEN], tpath[MAXPATHLEN];
const char *tmpdir;
@@ -765,7 +783,7 @@
exit(EXIT_FAILURE);
}
(void)snprintf(buf, sizeof(buf), "%s > %s", fmt, tpath);
- (void)snprintf(cmd, sizeof(cmd), buf, p);
+ fixstring(cmd, sizeof(cmd), buf, p);
(void)system(cmd);
(void)close(fd);
if ((*pathp = strdup(tpath)) == NULL) {
@@ -842,7 +860,8 @@
static void
cat(char *fname)
{
- int fd, n;
+ int fd;
+ ssize_t n;
char buf[2048];
if ((fd = open(fname, O_RDONLY, 0)) < 0) {
@@ -851,7 +870,7 @@
exit(EXIT_FAILURE);
}
while ((n = read(fd, buf, sizeof(buf))) > 0)
- if (write(STDOUT_FILENO, buf, n) != n) {
+ if (write(STDOUT_FILENO, buf, (size_t)n) != n) {
warn("write");
(void)cleanup();
exit(EXIT_FAILURE);
@@ -898,11 +917,11 @@
* strip out flag argument and jump
*/
static void
-jump(char **argv, char *flag, char *name)
+jump(char **argv, const char *flag, const char *name)
{
char **arg;
- argv[0] = name;
+ argv[0] = __UNCONST(name);
for (arg = argv + 1; *arg; ++arg)
if (!strcmp(*arg, flag))
break;
diff -r 1643c4055158 -r 847e366a5db8 usr.bin/man/manconf.c
--- a/usr.bin/man/manconf.c Thu Jul 18 15:31:49 2013 +0000
+++ b/usr.bin/man/manconf.c Thu Jul 18 15:39:08 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: manconf.c,v 1.6 2008/03/08 15:48:27 christos Exp $ */
+/* $NetBSD: manconf.c,v 1.7 2013/07/18 15:39:08 christos Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
@@ -45,7 +45,7 @@
#if 0
static char sccsid[] = "@(#)config.c 8.8 (Berkeley) 1/31/95";
#else
-__RCSID("$NetBSD: manconf.c,v 1.6 2008/03/08 15:48:27 christos Exp $");
+__RCSID("$NetBSD: manconf.c,v 1.7 2013/07/18 15:39:08 christos Exp $");
#endif
#endif /* not lint */
@@ -172,8 +172,8 @@
* section entries can either be all absolute
* paths or all relative paths, but not both.
*/
- type = (TAILQ_FIRST(&tp->entrylist) != NULL) ?
- *(TAILQ_FIRST(&tp->entrylist)->s) : 0;
+ type = (char)((TAILQ_FIRST(&tp->entrylist) != NULL) ?
+ *(TAILQ_FIRST(&tp->entrylist)->s) : '\0');
for (++t; (p = strtok(t, " \t\n")) != NULL; t = NULL) {
Home |
Main Index |
Thread Index |
Old Index