Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen Simplify a bit and constify as well. Since the...



details:   https://anonhg.NetBSD.org/src/rev/cc8b3f43728f
branches:  trunk
changeset: 778221:cc8b3f43728f
user:      matt <matt%NetBSD.org@localhost>
date:      Tue Mar 20 00:31:24 2012 +0000

description:
Simplify a bit and constify as well.  Since the file is mapped read-only,
use const references to access its data.

diffstat:

 lib/libc/gen/nlist_ecoff.c |  28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diffs (93 lines):

diff -r c19a163da34e -r cc8b3f43728f lib/libc/gen/nlist_ecoff.c
--- a/lib/libc/gen/nlist_ecoff.c        Tue Mar 20 00:16:35 2012 +0000
+++ b/lib/libc/gen/nlist_ecoff.c        Tue Mar 20 00:31:24 2012 +0000
@@ -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 @@
 
 #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 @@
         */
        if (check(0, sizeof *exechdrp))
                goto unmap;
-       exechdrp = mappedfile;
+       exechdrp = (const void *)mappedfile;
 
        if (ECOFF_BADMAG(exechdrp))
                goto unmap;
@@ -121,12 +121,12 @@
        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 @@
        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 @@
 done:
        rv = nent;
 unmap:
-       munmap(mappedfile, mappedsize);
+       munmap(__UNCONST(mappedfile), mappedsize);
 out:
        return rv;
 }



Home | Main Index | Thread Index | Old Index