Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/gen/getcap.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/gen/getcap.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.40 retrieving revision 1.45 diff -u -p -r1.40 -r1.45 --- src/lib/libc/gen/getcap.c 2004/04/23 14:47:52 1.40 +++ src/lib/libc/gen/getcap.c 2006/04/02 03:26:03 1.45 @@ -1,4 +1,4 @@ -/* $NetBSD: getcap.c,v 1.40 2004/04/23 14:47:52 christos Exp $ */ +/* $NetBSD: getcap.c,v 1.45 2006/04/02 03:26:03 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,17 +41,21 @@ #if 0 static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #else -__RCSID("$NetBSD: getcap.c,v 1.40 2004/04/23 14:47:52 christos Exp $"); +__RCSID("$NetBSD: getcap.c,v 1.45 2006/04/02 03:26:03 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifndef SMALL #include "namespace.h" +#endif #include #include #include #include +#ifndef SMALL #include +#endif #include #include #include @@ -87,7 +91,9 @@ static size_t topreclen; /* toprec leng static char *toprec; /* Additional record specified by cgetset() */ static int gottoprec; /* Flag indicating retrieval of toprecord */ +#ifndef SMALL static int cdbget(DB *, char **, const char *); +#endif static int getent(char **, size_t *, const char * const *, int, const char *, int, char *); static int nfcmp(char *, char *); @@ -207,6 +213,7 @@ cgetcap(buf, cap, type) * encountered (couldn't open/read a file, etc.), and -3 if a potential * reference loop is detected. */ +/* coverity[+alloc : arg-*0] */ int cgetent(char **buf, const char * const *db_array, const char *name) { @@ -237,18 +244,23 @@ cgetent(char **buf, const char * const * * names interpolated, a name can't be found, or depth exceeds * MAX_RECURSION. */ +/* coverity[+alloc : arg-*0] */ static int getent(char **cap, size_t *len, const char * const *db_array, int fd, const char *name, int depth, char *nfield) { +#ifndef SMALL DB *capdbp; + char pbuf[MAXPATHLEN]; + char *cbuf; + int retval; + size_t clen; +#endif + char *record, *newrecord; char *r_end, *rp = NULL; /* pacify gcc */ const char * const *db_p; - int myfd = 0, eof, foundit, retval; - size_t clen; - char *record, *cbuf, *newrecord; + int myfd = 0, eof, foundit; int tc_not_resolved; - char pbuf[MAXPATHLEN]; _DIAGASSERT(cap != NULL); _DIAGASSERT(len != NULL); @@ -301,6 +313,7 @@ getent(char **cap, size_t *len, const ch if (fd >= 0) { (void)lseek(fd, (off_t)0, SEEK_SET); } else { +#ifndef SMALL (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) != NULL) { @@ -325,7 +338,9 @@ getent(char **cap, size_t *len, const ch *len = clen; *cap = cbuf; return (retval); - } else { + } else +#endif + { fd = open(*db_p, O_RDONLY, 0); if (fd < 0) { /* No error on unfound file. */ @@ -632,6 +647,7 @@ tc_exp: { return (0); } +#ifndef SMALL static int cdbget(DB *capdbp, char **bp, const char *name) { @@ -642,8 +658,7 @@ cdbget(DB *capdbp, char **bp, const char _DIAGASSERT(bp != NULL); _DIAGASSERT(name != NULL); - /* LINTED key is not modified */ - key.data = (char *)name; + key.data = __UNCONST(name); key.size = strlen(name); for (;;) { @@ -666,6 +681,7 @@ cdbget(DB *capdbp, char **bp, const char *bp = (char *)data.data + 1; return (((char *)(data.data))[0] == TCERR ? 1 : 0); } +#endif /* * Cgetmatch will return 0 if name is one of the names of the capability @@ -747,10 +763,11 @@ cgetclose(void) * specified by db_array. It returns 0 upon completion of the database, 1 * upon returning an entry with more remaining, and -1 if an error occurs. */ +/* coverity[+alloc : arg-*0] */ int cgetnext(char **bp, const char * const *db_array) { - size_t len; + size_t len = 0; int status, done; char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; size_t dummy; @@ -771,7 +788,9 @@ cgetnext(char **bp, const char * const * line = toprec; } else { line = fgetln(pfp, &len); - if (line == NULL && pfp) { + if (line == NULL) { + if (pfp == NULL) + return -1; if (ferror(pfp)) { (void)cgetclose(); return (-1);