From 221383bcb1f9de839727b6ffd1b5a2b725314779 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 10 Sep 2012 12:18:59 +0200 Subject: maint: use xasprintf in place of xmalloc+sprintf * bootstrap.conf (gnulib_modules): Add gnulib's xvasprintf module. * src/util.c: Include "xvasprintf.h". (begin_output): Use xasprintf in place of xmalloc+sprintf. --- bootstrap.conf | 1 + src/util.c | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 3954c4d..81b318e 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -81,6 +81,7 @@ xalloc xfreopen xreadlink xstrtoumax +xvasprintf ' # Additional xgettext options to use. Use "\\\newline" to break lines. diff --git a/src/util.c b/src/util.c index 868b7e8..c02d156 100644 --- a/src/util.c +++ b/src/util.c @@ -23,6 +23,7 @@ #include #include #include +#include "xvasprintf.h" char const pr_program[] = PR_PROGRAM; @@ -262,14 +263,12 @@ begin_output (void) names[1] = c_escape (current_name1); /* Construct the header of this piece of diff. */ - name = xmalloc (strlen (names[0]) + strlen (names[1]) + strlen (switch_string) + 7); - /* POSIX 1003.1-2001 specifies this format. But there are some bugs in the standard: it says that we must print only the last component of the pathnames, and it requires two spaces after "diff" if there are no options. These requirements are silly and do not match historical practice. */ - sprintf (name, "diff%s %s %s", switch_string, names[0], names[1]); + name = xasprintf ("diff%s %s %s", switch_string, names[0], names[1]); if (paginate) { -- cgit v1.2.1