Re: [PATCH v2 04/14] dir: select directories correctly
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Sep 15, 2021, 16:43 UTC
- Message-ID
- <3252cc19-46ec-bbbe-6a02-fe02cb767dff@gmail.com>
- In-Reply-To
- <CABPp-BFitDu8UFkH5Syd3w7_e4sT5nJCJ_6N5sn3a+Acv6B4aQ@mail.gmail.com>
On 9/15/2021 10:54 AM, Elijah Newren wrote:
Show 17 quoted lines
>> + /*
>> + * Use 'alloc' as an indicator that the string has not been
>> + * initialized, in case the parent is the root directory.
>> + */
>> + if (!path_parent->alloc) {
>> + char *slash;
>> + strbuf_addstr(path_parent, pathname);
>> + slash = find_last_dir_sep(path_parent->buf);
>> +
>> + if (slash)
>> + *slash = '\0';
>
> Are you breaking strbuf invariants here? path_parent->len will not be
> corrected by this string manipulation. Perhaps replace this if-else
> block with
>
> strbuf_setlen(path_parent, slash ? slash - path_parent->buf : 0)Yes, I am. I noticed and fixed this when I was rewriting this patch for Ævar's feedback. Thanks for pointing it out.
Thanks, -Stolee