From 2678fcfdf586236aff9f78bdbc1e6800566e84ed Mon Sep 17 00:00:00 2001 From: roy Date: Tue, 16 May 2017 09:19:48 +0000 Subject: [PATCH] Don't bother allocating space for the database name, just print directly to the static buffer storage. --- lib/libterminfo/term.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/libterminfo/term.c b/lib/libterminfo/term.c index 9bea2020baca..410e4e417885 100644 --- a/lib/libterminfo/term.c +++ b/lib/libterminfo/term.c @@ -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 -__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 @@ -46,7 +46,7 @@ __RCSID("$NetBSD: term.c,v 1.23 2017/05/16 08:52:14 roy Exp $"); #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 @@ _ti_dbgetterm(TERMINAL *term, const char *path, const char *name, int flags) { 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 @@ _ti_dbgetterm(TERMINAL *term, const char *path, const char *name, int flags) 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 @@ _ti_findterm(TERMINAL *term, const char *name, int flags) _DIAGASSERT(term != NULL); _DIAGASSERT(name != NULL); - database[0] = '\0'; + __ti_database[0] = '\0'; _ti_database = NULL; r = 0;