[hackers] [sbase] libutil/recurse: Simplify adding trailing slash || Michael Forney

From: <git_AT_suckless.org>
Date: Sun, 21 Jun 2020 07:20:29 +0200 (CEST)

commit fdb9084da94067627941f4f7ee414c447866006a
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sat Jun 20 18:21:35 2020 -0700
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Sat Jun 20 18:48:14 2020 -0700

    libutil/recurse: Simplify adding trailing slash
    
    We know that r->pathlen < sizeof(r->path) since r->path is
    nul-terminated, so we can safely add a '/' here. If there is no
    space left over for the rest of the path and nul-terminator, this
    will be caught by the subsequent estrlcpy.

diff --git a/libutil/recurse.c b/libutil/recurse.c
index feb1b30..e66efaf 100644
--- a/libutil/recurse.c
+++ b/libutil/recurse.c
_AT_@ -70,7 +70,7 @@ recurse(int dirfd, const char *name, void *data, struct recursor *r)
                         return;
                 }
                 if (r->path[pathlen - 1] != '/')
- pathlen += estrlcpy(r->path + pathlen, "/", sizeof(r->path) - pathlen);
+ r->path[pathlen++] = '/';
                 if (r->follow == 'H')
                         flags |= AT_SYMLINK_NOFOLLOW;
                 while ((d = readdir(dp))) {
Received on Sun Jun 21 2020 - 07:20:29 CEST

This archive was generated by hypermail 2.3.0 : Sun Jun 21 2020 - 07:24:31 CEST