[1/2] use __strchrnul instead of strchr and strlen

Submitted by Frediano Ziglio on March 26, 2019, 9:36 a.m.

Details

Message ID 20190326093648.5669-1-fziglio@redhat.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Frediano Ziglio March 26, 2019, 9:36 a.m.
The result is the same but takes less code.
Note that __execvpe calls getenv which calls __strchrnul so even
using static output the size of the executable won't grow.
---
 src/process/execvp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/process/execvp.c b/src/process/execvp.c
index 1fdf036f..ef3b9dd5 100644
--- a/src/process/execvp.c
+++ b/src/process/execvp.c
@@ -28,8 +28,7 @@  int __execvpe(const char *file, char *const argv[], char *const envp[])
 
 	for(p=path; ; p=z) {
 		char b[l+k+1];
-		z = strchr(p, ':');
-		if (!z) z = p+strlen(p);
+		z = __strchrnul(p, ':');
 		if (z-p >= l) {
 			if (!*z++) break;
 			continue;

Comments

Frediano Ziglio April 2, 2019, 9:57 a.m.
ping

> 
> The result is the same but takes less code.
> Note that __execvpe calls getenv which calls __strchrnul so even
> using static output the size of the executable won't grow.
> ---
>  src/process/execvp.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/src/process/execvp.c b/src/process/execvp.c
> index 1fdf036f..ef3b9dd5 100644
> --- a/src/process/execvp.c
> +++ b/src/process/execvp.c
> @@ -28,8 +28,7 @@ int __execvpe(const char *file, char *const argv[], char
> *const envp[])
>  
>  	for(p=path; ; p=z) {
>  		char b[l+k+1];
> -		z = strchr(p, ':');
> -		if (!z) z = p+strlen(p);
> +		z = __strchrnul(p, ':');
>  		if (z-p >= l) {
>  			if (!*z++) break;
>  			continue;
Rich Felker April 2, 2019, 2:40 p.m.
On Tue, Apr 02, 2019 at 05:57:33AM -0400, Frediano Ziglio wrote:
> ping

Thanks for the ping. Applying!

Rich


> > The result is the same but takes less code.
> > Note that __execvpe calls getenv which calls __strchrnul so even
> > using static output the size of the executable won't grow.
> > ---
> >  src/process/execvp.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/src/process/execvp.c b/src/process/execvp.c
> > index 1fdf036f..ef3b9dd5 100644
> > --- a/src/process/execvp.c
> > +++ b/src/process/execvp.c
> > @@ -28,8 +28,7 @@ int __execvpe(const char *file, char *const argv[], char
> > *const envp[])
> >  
> >  	for(p=path; ; p=z) {
> >  		char b[l+k+1];
> > -		z = strchr(p, ':');
> > -		if (!z) z = p+strlen(p);
> > +		z = __strchrnul(p, ':');
> >  		if (z-p >= l) {
> >  			if (!*z++) break;
> >  			continue;