Module Name: src Committed By: matt Date: Tue Mar 20 00:31:24 UTC 2012
Modified Files: src/lib/libc/gen: nlist_ecoff.c Log Message: Simplify a bit and constify as well. Since the file is mapped read-only, use const references to access its data. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/lib/libc/gen/nlist_ecoff.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/gen/nlist_ecoff.c diff -u src/lib/libc/gen/nlist_ecoff.c:1.22 src/lib/libc/gen/nlist_ecoff.c:1.23 --- src/lib/libc/gen/nlist_ecoff.c:1.22 Tue Mar 20 00:16:35 2012 +++ src/lib/libc/gen/nlist_ecoff.c Tue Mar 20 00:31:24 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: nlist_ecoff.c,v 1.22 2012/03/20 00:16:35 christos Exp $ */ +/* $NetBSD: nlist_ecoff.c,v 1.23 2012/03/20 00:31:24 matt Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou @@ -36,7 +36,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nlist_ecoff.c,v 1.22 2012/03/20 00:16:35 christos Exp $"); +__RCSID("$NetBSD: nlist_ecoff.c,v 1.23 2012/03/20 00:31:24 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -59,17 +59,17 @@ __RCSID("$NetBSD: nlist_ecoff.c,v 1.22 2 #ifdef NLIST_ECOFF #define check(off, size) \ - (/*CONSTCOND*/(off < 0) || ((size_t)(off + size) > mappedsize)) + ((size_t)off >= mappedsize || (size_t)(off + size) > mappedsize) int __fdnlist_ecoff(int fd, struct nlist *list) { struct nlist *p; - struct ecoff_exechdr *exechdrp; - struct ecoff_symhdr *symhdrp; - struct ecoff_extsym *esyms; + const struct ecoff_exechdr *exechdrp; + const struct ecoff_symhdr *symhdrp; + const struct ecoff_extsym *esyms; struct stat st; - char *mappedfile; + const char *mappedfile; size_t mappedsize; u_long symhdroff, extstroff; u_int symhdrsize; @@ -107,7 +107,7 @@ __fdnlist_ecoff(int fd, struct nlist *li */ if (check(0, sizeof *exechdrp)) goto unmap; - exechdrp = mappedfile; + exechdrp = (const void *)mappedfile; if (ECOFF_BADMAG(exechdrp)) goto unmap; @@ -121,12 +121,12 @@ __fdnlist_ecoff(int fd, struct nlist *li if ((symhdroff + sizeof *symhdrp) > mappedsize || sizeof *symhdrp != symhdrsize) goto unmap; - symhdrp = (void *)&mappedfile[symhdroff]; + symhdrp = (const void *)&mappedfile[symhdroff]; nesyms = symhdrp->esymMax; if (check(symhdrp->cbExtOffset, nesyms * sizeof *esyms)) goto unmap; - esyms = (void *)&mappedfile[symhdrp->cbExtOffset]; + esyms = (const void *)&mappedfile[symhdrp->cbExtOffset]; extstroff = symhdrp->cbSsExtOffset; /* @@ -149,15 +149,15 @@ __fdnlist_ecoff(int fd, struct nlist *li for (i = 0; i < nesyms; i++) { for (p = list; !ISLAST(p); p++) { const char *nlistname; - char *symtabname; + const char *symtabname; /* This may be incorrect */ nlistname = N_NAME(p); if (*nlistname == '_') nlistname++; - symtabname = (void *)&mappedfile[extstroff - + esyms[i].es_strindex]; + symtabname = + &mappedfile[extstroff + esyms[i].es_strindex]; if (!strcmp(symtabname, nlistname)) { /* @@ -178,7 +178,7 @@ __fdnlist_ecoff(int fd, struct nlist *li done: rv = nent; unmap: - munmap(mappedfile, mappedsize); + munmap(__UNCONST(mappedfile), mappedsize); out: return rv; }