Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/tpfmt - pass lint



details:   https://anonhg.NetBSD.org/src/rev/7fdf59761663
branches:  trunk
changeset: 759007:7fdf59761663
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 24 13:17:56 2010 +0000

description:
- pass lint
- minor spacing nits
- check allocations

diffstat:

 usr.bin/tpfmt/Makefile |   4 +++-
 usr.bin/tpfmt/sym.c    |  25 +++++++++++--------------
 usr.bin/tpfmt/sym.h    |   4 ++--
 usr.bin/tpfmt/tpfmt.c  |  27 +++++++++++++++------------
 4 files changed, 31 insertions(+), 29 deletions(-)

diffs (218 lines):

diff -r 2f18a2846001 -r 7fdf59761663 usr.bin/tpfmt/Makefile
--- a/usr.bin/tpfmt/Makefile    Wed Nov 24 11:40:24 2010 +0000
+++ b/usr.bin/tpfmt/Makefile    Wed Nov 24 13:17:56 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.1 2010/11/23 20:48:40 yamt Exp $
+#      $NetBSD: Makefile,v 1.2 2010/11/24 13:17:56 christos Exp $
 
 PROG=  tpfmt
 NOMAN= 
@@ -8,8 +8,10 @@
 
 LDADD+= -lpthread
 LDADD+= -lelf
+LDADD+= -lutil
 DPADD+= ${LIBPTHREAD}
 DPADD+= ${LIBELF}
+DPADD+= ${LIBUTIL}
 
 .include <bsd.own.mk>
 .include <bsd.prog.mk>
diff -r 2f18a2846001 -r 7fdf59761663 usr.bin/tpfmt/sym.c
--- a/usr.bin/tpfmt/sym.c       Wed Nov 24 11:40:24 2010 +0000
+++ b/usr.bin/tpfmt/sym.c       Wed Nov 24 13:17:56 2010 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: sym.c,v 1.1 2010/11/23 20:48:40 yamt Exp $     */
+/*     $NetBSD: sym.c,v 1.2 2010/11/24 13:17:56 christos Exp $ */
 
 /*-
- * Copyright (c)2010 YAMAMOTO Takashi,
+ * Copyright (c) 2010 YAMAMOTO Takashi,
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: sym.c,v 1.1 2010/11/23 20:48:40 yamt Exp $");
+__RCSID("$NetBSD: sym.c,v 1.2 2010/11/24 13:17:56 christos Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -39,6 +39,7 @@
 #include <libelf.h>
 #include <stdlib.h>
 #include <string.h>
+#include <util.h>
 
 #include "sym.h"
 
@@ -49,7 +50,7 @@
 };
 
 static struct sym **syms = NULL;
-static unsigned int nsyms = 0;
+static size_t nsyms = 0;
 
 static int
 compare_value(const void *p1, const void *p2)
@@ -74,8 +75,7 @@
        GElf_Shdr *sh;
        Elf_Data *d;
        int fd;
-       size_t size;
-       unsigned int i;
+       size_t size, i;
 
        fd = open(ksyms, O_RDONLY);
        if (fd == -1) {
@@ -111,22 +111,19 @@
                GElf_Sym *st;
                struct sym *sym;
 
-               st = gelf_getsym(d, i, &st_store);
+               st = gelf_getsym(d, (int)i, &st_store);
                if (st == NULL) {
                        goto elffail;
                }
                if (ELF_ST_TYPE(st->st_info) != STT_FUNC) {
                        continue;
                }
-               sym = malloc(sizeof(*sym));
-               sym->name = strdup(elf_strptr(e, sh->sh_link, st->st_name));
+               sym = emalloc(sizeof(*sym));
+               sym->name = estrdup(elf_strptr(e, sh->sh_link, st->st_name));
                sym->value = (uint64_t)st->st_value;
                sym->size = st->st_size;
                nsyms++;
-               syms = realloc(syms, sizeof(*syms) * nsyms);
-               if (syms == NULL) {
-                       err(EXIT_FAILURE, "realloc");
-               }
+               syms = erealloc(syms, sizeof(*syms) * nsyms);
                syms[nsyms - 1] = sym;
        }
        qsort(syms, nsyms, sizeof(*syms), compare_value);
@@ -138,7 +135,7 @@
 const char *
 ksymlookup(uint64_t value, uint64_t *offset)
 {
-       unsigned int i;
+       size_t i;
 
        for (i = 0; i < nsyms; i++) {
                const struct sym *sym = syms[i];
diff -r 2f18a2846001 -r 7fdf59761663 usr.bin/tpfmt/sym.h
--- a/usr.bin/tpfmt/sym.h       Wed Nov 24 11:40:24 2010 +0000
+++ b/usr.bin/tpfmt/sym.h       Wed Nov 24 13:17:56 2010 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: sym.h,v 1.1 2010/11/23 20:48:40 yamt Exp $     */
+/*     $NetBSD: sym.h,v 1.2 2010/11/24 13:17:56 christos Exp $ */
 
 /*-
- * Copyright (c)2010 YAMAMOTO Takashi,
+ * Copyright (c) 2010 YAMAMOTO Takashi,
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
diff -r 2f18a2846001 -r 7fdf59761663 usr.bin/tpfmt/tpfmt.c
--- a/usr.bin/tpfmt/tpfmt.c     Wed Nov 24 11:40:24 2010 +0000
+++ b/usr.bin/tpfmt/tpfmt.c     Wed Nov 24 13:17:56 2010 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: tpfmt.c,v 1.1 2010/11/23 20:48:40 yamt Exp $   */
+/*     $NetBSD: tpfmt.c,v 1.2 2010/11/24 13:17:56 christos Exp $       */
 
 /*-
- * Copyright (c)2010 YAMAMOTO Takashi,
+ * Copyright (c) 2010 YAMAMOTO Takashi,
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: tpfmt.c,v 1.1 2010/11/23 20:48:40 yamt Exp $");
+__RCSID("$NetBSD: tpfmt.c,v 1.2 2010/11/24 13:17:56 christos Exp $");
 #endif /* not lint */
 
 #include <sys/rbtree.h>
@@ -40,10 +40,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <util.h>
 
 #include "sym.h"
 
-const char *ksyms = "/dev/ksyms";
+static const char ksyms[] = "/dev/ksyms";
 
 struct addr {
        struct rb_node node;
@@ -51,9 +52,10 @@
        unsigned int nsamples;  /* number of samples taken for the address */
 };
 
-rb_tree_t addrtree;
+static rb_tree_t addrtree;
 
 static signed int
+/*ARGSUSED1*/
 addrtree_compare_key(void *ctx, const void *n1, const void *keyp)
 {
        const struct addr *a1 = n1;
@@ -95,13 +97,13 @@
 }
 
 int
+/*ARGSUSED*/
 main(int argc, char *argv[])
 {
        struct addr *a;
        struct addr **l;
        struct addr **p;
-       unsigned int naddrs;
-       unsigned int i;
+       size_t naddrs, i;
 
        ksymload(ksyms);
        rb_tree_init(&addrtree, &addrtree_ops);
@@ -124,7 +126,7 @@
                                err(EXIT_FAILURE, "fread");
                        }
                }
-               a = malloc(sizeof(*a));
+               a = emalloc(sizeof(*a));
                a->addr = (uint64_t)sample;
                a->nsamples = 1;
                o = rb_tree_insert_node(&addrtree, a);
@@ -140,7 +142,7 @@
         * sort samples by addresses.
         */
 
-       l = malloc(naddrs * sizeof(*l));
+       l = emalloc(naddrs * sizeof(*l));
        p = l;
        RB_TREE_FOREACH(a, &addrtree) {
                *p++ = a;
@@ -161,14 +163,15 @@
                a = l[i];
                name = ksymlookup(a->addr, &offset);
                if (name == NULL) {
-                       snprintf(buf, sizeof(buf), "<%016" PRIx64 ">", a->addr);
+                       (void)snprintf(buf, sizeof(buf), "<%016" PRIx64 ">",
+                           a->addr);
                        name = buf;
                } else if (offset != 0) {
-                       snprintf(buf, sizeof(buf), "%s+0x%" PRIx64, name,
+                       (void)snprintf(buf, sizeof(buf), "%s+0x%" PRIx64, name,
                            offset);
                        name = buf;
                }
                printf("%8u %016" PRIx64 " %s\n", a->nsamples, a->addr, name);
        }
-       exit(EXIT_SUCCESS);
+       return EXIT_SUCCESS;
 }



Home | Main Index | Thread Index | Old Index