From 924826a817e397c89509963a1d13d951c9d51ce5 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 9 Feb 2017 20:25:59 -0500 Subject: bftw: Make the nameoff of "///" point to "/" This simplifies a few things such as -name handling for ///. --- eval.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 3a97585..512a05a 100644 --- a/eval.c +++ b/eval.c @@ -286,7 +286,6 @@ static const char *exec_format_path(const struct expr *expr, const struct BFTW * if (name[0] == '/') { // Must be a root path ("/", "//", etc.) - assert(ftwbuf->nameoff == 0); return name; } @@ -311,7 +310,7 @@ err: } static void exec_free_path(const char *path, const struct BFTW *ftwbuf) { - if (path != ftwbuf->path) { + if (path != ftwbuf->path && path != ftwbuf->path + ftwbuf->nameoff) { dstrfree((char *)path); } } @@ -630,16 +629,12 @@ bool eval_name(const struct expr *expr, struct eval_state *state) { // Any trailing slashes are not part of the name. This can only // happen for the root path. const char *slash = strchr(name, '/'); - if (slash == name) { - // The name of "/" (or "//", etc.) is "/" - name = "/"; - } else if (slash) { - copy = strdup(name); + if (slash && slash > name) { + copy = strndup(name, slash - name); if (!copy) { eval_error(state); return false; } - copy[slash - name] = '\0'; name = copy; } } -- cgit v1.2.3