Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Apr 2016 14:09:14 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r297749 - stable/10/bin/sh
Message-ID:  <201604091409.u39E9EJP082370@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sat Apr  9 14:09:14 2016
New Revision: 297749
URL: https://svnweb.freebsd.org/changeset/base/297749

Log:
  MFC r278818: sh: Add stsavestr(), like savestr() but allocates using
  stalloc().

Modified:
  stable/10/bin/sh/cd.c
  stable/10/bin/sh/expand.c
  stable/10/bin/sh/memalloc.c
  stable/10/bin/sh/memalloc.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/cd.c
==============================================================================
--- stable/10/bin/sh/cd.c	Sat Apr  9 13:58:04 2016	(r297748)
+++ stable/10/bin/sh/cd.c	Sat Apr  9 14:09:14 2016	(r297749)
@@ -182,7 +182,6 @@ cdlogical(char *dest)
 	struct stat statb;
 	int first;
 	int badstat;
-	size_t len;
 
 	/*
 	 *  Check each component of the path. If we find a symlink or
@@ -190,9 +189,7 @@ cdlogical(char *dest)
 	 *  next time we get the value of the current directory.
 	 */
 	badstat = 0;
-	len = strlen(dest);
-	cdcomppath = stalloc(len + 1);
-	memcpy(cdcomppath, dest, len + 1);
+	cdcomppath = stsavestr(dest);
 	STARTSTACKSTR(p);
 	if (*dest == '/') {
 		STPUTC('/', p);
@@ -277,7 +274,6 @@ findcwd(char *dir)
 {
 	char *new;
 	char *p;
-	size_t len;
 
 	/*
 	 * If our argument is NULL, we don't know the current directory
@@ -286,9 +282,7 @@ findcwd(char *dir)
 	 */
 	if (dir == NULL || curdir == NULL)
 		return getpwd2();
-	len = strlen(dir);
-	cdcomppath = stalloc(len + 1);
-	memcpy(cdcomppath, dir, len + 1);
+	cdcomppath = stsavestr(dir);
 	STARTSTACKSTR(new);
 	if (*dir != '/') {
 		STPUTS(curdir, new);

Modified: stable/10/bin/sh/expand.c
==============================================================================
--- stable/10/bin/sh/expand.c	Sat Apr  9 13:58:04 2016	(r297748)
+++ stable/10/bin/sh/expand.c	Sat Apr  9 14:09:14 2016	(r297749)
@@ -1281,11 +1281,8 @@ addfname(char *name)
 {
 	char *p;
 	struct strlist *sp;
-	size_t len;
 
-	len = strlen(name);
-	p = stalloc(len + 1);
-	memcpy(p, name, len + 1);
+	p = stsavestr(name);
 	sp = (struct strlist *)stalloc(sizeof *sp);
 	sp->text = p;
 	*exparg.lastp = sp;

Modified: stable/10/bin/sh/memalloc.c
==============================================================================
--- stable/10/bin/sh/memalloc.c	Sat Apr  9 13:58:04 2016	(r297748)
+++ stable/10/bin/sh/memalloc.c	Sat Apr  9 14:09:14 2016	(r297749)
@@ -180,6 +180,18 @@ stunalloc(pointer p)
 }
 
 
+char *
+stsavestr(const char *s)
+{
+	char *p;
+	size_t len;
+
+	len = strlen(s);
+	p = stalloc(len + 1);
+	memcpy(p, s, len + 1);
+	return p;
+}
+
 
 void
 setstackmark(struct stackmark *mark)

Modified: stable/10/bin/sh/memalloc.h
==============================================================================
--- stable/10/bin/sh/memalloc.h	Sat Apr  9 13:58:04 2016	(r297748)
+++ stable/10/bin/sh/memalloc.h	Sat Apr  9 14:09:14 2016	(r297749)
@@ -52,6 +52,7 @@ void ckfree(pointer);
 char *savestr(const char *);
 pointer stalloc(int);
 void stunalloc(pointer);
+char *stsavestr(const char *);
 void setstackmark(struct stackmark *);
 void popstackmark(struct stackmark *);
 char *growstackstr(void);



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