From c1a67b39611f3e396121cf5333b0e77b537e9741 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 6 Sep 2021 10:00:00 +0000 Subject: Use xasprintf instead of asprintf followed by error(EXIT_FAILURE) Signed-off-by: Dmitry V. Levin --- lib/ChangeLog | 3 +++ lib/color.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/ChangeLog b/lib/ChangeLog index 468001f8..96eaa330 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,8 @@ 2021-09-06 Dmitry V. Levin + * color.c (parse_opt): Replace asprintf followed by error(EXIT_FAILURE) + with xasprintf. + * xasprintf.c: New file. * Makefile.am (libeu_a_SOURCES): Add it. * libeu.h (xasprintf): New prototype. diff --git a/lib/color.c b/lib/color.c index 454cb7ca..e43b6143 100644 --- a/lib/color.c +++ b/lib/color.c @@ -188,10 +188,8 @@ valid arguments are:\n\ if (name_len == known[i].len && memcmp (start, known[i].name, name_len) == 0) { - if (asprintf (known[i].varp, "\e[%.*sm", - (int) (env - val), val) < 0) - error (EXIT_FAILURE, errno, - _("cannot allocate memory")); + *known[i].varp = + xasprintf ("\e[%.*sm", (int) (env - val), val); break; } } -- cgit v1.2.3