From: Jean-Noël AVILA Date: Tue, 15 Jan 2013 19:14:28 GMT Subject: Re: [PATCH] attr: fix off-by-one directory component length calculation Message-ID: <201301152014.28433.avila.jn@gmail.com> In-Reply-To: <1358256924-31578-1-git-send-email-pclouds@gmail.com> Thank you for the explanation. I did not monitor the system calls when writing that patch. Where is the perf framework? As the mistake is located in the "find_basename" function, I would propose a fix directly into it so that the output fits what the other functions expect. Something in the line of: diff --git a/attr.c b/attr.c index d6d7190..b6e72f3 100644 --- a/attr.c +++ b/attr.c @@ -572,7 +572,7 @@ static const char *find_basename(const char *path) if (*cp == '/' && cp[1]) last_slash = cp; } - return last_slash ? last_slash + 1 : path; + return last_slash ? last_slash : path; } static void prepare_attr_stack(const char *path) @@ -770,6 +770,10 @@ static void collect_all_attrs(const char *path) check_all_attr[i].value = ATTR__UNKNOWN; basename = find_basename(path); + /* the slash is included in the basename + so that it can be matched by a directory pattern */ + if (basename != path) + basename++; pathlen = strlen(path); rem = attr_nr; for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)