Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo Don't bother allocating space for the databa...



details:   https://anonhg.NetBSD.org/src/rev/dab95ea6bcef
branches:  trunk
changeset: 353655:dab95ea6bcef
user:      roy <roy%NetBSD.org@localhost>
date:      Tue May 16 09:19:48 2017 +0000

description:
Don't bother allocating space for the database name, just print
directly to the static buffer storage.

diffstat:

 lib/libterminfo/term.c |  18 +++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)

diffs (65 lines):

diff -r 4e33bc85e255 -r dab95ea6bcef lib/libterminfo/term.c
--- a/lib/libterminfo/term.c    Tue May 16 08:52:14 2017 +0000
+++ b/lib/libterminfo/term.c    Tue May 16 09:19:48 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: term.c,v 1.23 2017/05/16 08:52:14 roy Exp $ */
+/* $NetBSD: term.c,v 1.24 2017/05/16 09:19:48 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: term.c,v 1.23 2017/05/16 08:52:14 roy Exp $");
+__RCSID("$NetBSD: term.c,v 1.24 2017/05/16 09:19:48 roy Exp $");
 
 #include <sys/stat.h>
 
@@ -46,7 +46,7 @@
 
 #define _PATH_TERMINFO         "/usr/share/misc/terminfo"
 
-static char database[PATH_MAX];
+static char __ti_database[PATH_MAX];
 const char *_ti_database;
 
 /* Include a generated list of pre-compiled terminfo descriptions. */
@@ -247,16 +247,13 @@
 {
        struct cdbr *db;
        const void *data;
-       char *db_name;
        const uint8_t *data8;
        size_t len, klen;
        int r;
 
-       if (asprintf(&db_name, "%s.cdb", path) < 0)
+       if (snprintf(__ti_database, sizeof(__ti_database), "%s.cdb", path) < 0)
                return -1;
-
-       db = cdbr_open(db_name, CDBR_DEFAULT);
-       free(db_name);
+       db = cdbr_open(__ti_database, CDBR_DEFAULT);
        if (db == NULL)
                return -1;
 
@@ -284,8 +281,7 @@
        else if (memcmp(data8 + 3, name, klen))
                goto fail;
 
-       strlcpy(database, path, sizeof(database));
-       _ti_database = database;
+       _ti_database = __ti_database;
 
        r = _ti_readterm(term, data, len, flags);
        cdbr_close(db);
@@ -363,7 +359,7 @@
        _DIAGASSERT(term != NULL);
        _DIAGASSERT(name != NULL);
 
-       database[0] = '\0';
+       __ti_database[0] = '\0';
        _ti_database = NULL;
        r = 0;
 



Home | Main Index | Thread Index | Old Index