Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Sep 2016 18:42:58 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r305993 - head/sbin/mount
Message-ID:  <201609191842.u8JIgwEf094038@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Mon Sep 19 18:42:58 2016
New Revision: 305993
URL: https://svnweb.freebsd.org/changeset/base/305993

Log:
  mount(1): Simplify by using asprintf(3)
  
  Instead of strlen() + malloc() + snprintf, just use asprintf().
  No functional change.
  
  Obtained from:	OpenBSD (CVS Rev. 1.67)

Modified:
  head/sbin/mount/mount.c

Modified: head/sbin/mount/mount.c
==============================================================================
--- head/sbin/mount/mount.c	Mon Sep 19 18:40:54 2016	(r305992)
+++ head/sbin/mount/mount.c	Mon Sep 19 18:42:58 2016	(r305993)
@@ -705,17 +705,14 @@ getmntpt(const char *name)
 char *
 catopt(char *s0, const char *s1)
 {
-	size_t i;
 	char *cp;
 
 	if (s1 == NULL || *s1 == '\0')
 		return (s0);
 
 	if (s0 && *s0) {
-		i = strlen(s0) + strlen(s1) + 1 + 1;
-		if ((cp = malloc(i)) == NULL)
-			errx(1, "malloc failed");
-		(void)snprintf(cp, i, "%s,%s", s0, s1);
+		if (asprintf(&cp, "%s,%s", s0, s1) == -1)
+			errx(1, "asprintf failed");
 	} else
 		cp = strdup(s1);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201609191842.u8JIgwEf094038>