Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/infocmp PR/50932: David Binderman: use emalloc/ereal...



details:   https://anonhg.NetBSD.org/src/rev/7d1aa98d0c37
branches:  trunk
changeset: 344013:7d1aa98d0c37
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Mar 09 20:02:33 2016 +0000

description:
PR/50932: David Binderman: use emalloc/erealloc/ecalloc

diffstat:

 usr.bin/infocmp/Makefile  |   6 +++---
 usr.bin/infocmp/infocmp.c |  27 +++++++++++----------------
 2 files changed, 14 insertions(+), 19 deletions(-)

diffs (105 lines):

diff -r 20605c60fc89 -r 7d1aa98d0c37 usr.bin/infocmp/Makefile
--- a/usr.bin/infocmp/Makefile  Wed Mar 09 19:53:32 2016 +0000
+++ b/usr.bin/infocmp/Makefile  Wed Mar 09 20:02:33 2016 +0000
@@ -1,9 +1,9 @@
-#      $NetBSD: Makefile,v 1.2 2013/08/11 06:48:46 dholland Exp $
+#      $NetBSD: Makefile,v 1.3 2016/03/09 20:02:33 christos Exp $
 
 PROG=          infocmp
 
 CPPFLAGS+=     -I${.CURDIR}/../../lib/libterminfo
-LDADD+=                -lterminfo
-DPADD+=                ${LIBTERMINFO}
+LDADD+=                -lterminfo -lutil
+DPADD+=                ${LIBTERMINFO} ${LIBUTIL}
 
 .include <bsd.prog.mk>
diff -r 20605c60fc89 -r 7d1aa98d0c37 usr.bin/infocmp/infocmp.c
--- a/usr.bin/infocmp/infocmp.c Wed Mar 09 19:53:32 2016 +0000
+++ b/usr.bin/infocmp/infocmp.c Wed Mar 09 20:02:33 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: infocmp.c,v 1.9 2016/02/24 13:31:54 roy Exp $ */
+/* $NetBSD: infocmp.c,v 1.10 2016/03/09 20:02:33 christos Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: infocmp.c,v 1.9 2016/02/24 13:31:54 roy Exp $");
+__RCSID("$NetBSD: infocmp.c,v 1.10 2016/03/09 20:02:33 christos Exp $");
 
 #include <sys/ioctl.h>
 
@@ -40,6 +40,7 @@
 #include <term_private.h>
 #include <term.h>
 #include <unistd.h>
+#include <util.h>
 
 #define SW 8
 
@@ -180,7 +181,7 @@
                                l = strlen(ents[i].id) + 3;
                        break;
                default:
-                       errx(1, "invalid type");
+                       errx(EXIT_FAILURE, "invalid type");
                }
                if (col != SW) {
                        if (col + l > cols) {
@@ -431,9 +432,7 @@
 {
        TERMINAL *t;
 
-       t = calloc(1, sizeof(*t));
-       if (t == NULL)
-               err(1, "calloc");
+       t = ecalloc(1, sizeof(*t));
        if (name == NULL)
                name = getenv("TERM");
        if (name == NULL)
@@ -442,9 +441,9 @@
                return t;
 
        if (_ti_database == NULL)
-               errx(1, "no terminal definition found in internal database");
+               errx(EXIT_FAILURE, "no terminal definition found in internal database");
        else
-               errx(1, "no terminal definition found in %s.db", _ti_database);
+               errx(EXIT_FAILURE, "no terminal definition found in %s.db", _ti_database);
 }
 
 static void
@@ -507,15 +506,13 @@
        TERMUSERDEF *ud, *tud;
        size_t i, j, agree, absent, data;
 
-       terms = malloc(sizeof(**terms) * nuse);
-       if (terms == NULL)
-               err(1, "malloc");
+       terms = ecalloc(nuse, sizeof(**terms));
        for (i = 0; i < nuse; i++) {
                if (strcmp(term->name, *uterms) == 0)
-                       errx(1, "cannot use same terminal");
+                       errx(EXIT_FAILURE, "cannot use same terminal");
                for (j = 0; j < i; j++)
                        if (strcmp(terms[j]->name, *uterms) == 0)
-                               errx(1, "cannot use same terminal");
+                               errx(EXIT_FAILURE, "cannot use same terminal");
                terms[i] = load_term(*uterms++);
        }
 
@@ -628,10 +625,8 @@
                        ud = find_userdef(term, terms[i]->_userdefs[j].id);
                        if (ud != NULL)
                                continue; /* We have handled this */
-                       term->_userdefs = realloc(term->_userdefs,
+                       term->_userdefs = erealloc(term->_userdefs,
                            sizeof(*term->_userdefs) * (term->_nuserdefs + 1));
-                       if (term->_userdefs == NULL)
-                               err(1, "malloc");
                        tud = &term->_userdefs[term->_nuserdefs++];
                        tud->id = terms[i]->_userdefs[j].id;
                        tud->type = terms[i]->_userdefs[j].flag;



Home | Main Index | Thread Index | Old Index