Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Dec 2012 17:50:39 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r243759 - head/lib/libc/gen
Message-ID:  <201212011750.qB1HodxR059717@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Sat Dec  1 17:50:39 2012
New Revision: 243759
URL: http://svnweb.freebsd.org/changeset/base/243759

Log:
  In globextend(), take advantage of the fact that realloc(NULL, size) is
  equivalent to malloc(size). This eliminates the conditional expression
  used for calling either realloc() or malloc() when realloc() will do
  all the time.

Modified:
  head/lib/libc/gen/glob.c

Modified: head/lib/libc/gen/glob.c
==============================================================================
--- head/lib/libc/gen/glob.c	Sat Dec  1 17:44:06 2012	(r243758)
+++ head/lib/libc/gen/glob.c	Sat Dec  1 17:50:39 2012	(r243759)
@@ -715,9 +715,8 @@ globextend(const Char *path, glob_t *pgl
 	}
 
 	newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
-	pathv = pglob->gl_pathv ?
-		    realloc((char *)pglob->gl_pathv, newsize) :
-		    malloc(newsize);
+	/* realloc(NULL, newsize) is equivalent to malloc(newsize). */
+	pathv = realloc((void *)pglob->gl_pathv, newsize);
 	if (pathv == NULL)
 		return (GLOB_NOSPACE);
 



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