Re: [PATCH 2/3] path: use the right datatype
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Mar 3, 2026, 13:42 UTC
- Message-ID
- <aablPlaCY-TAoCi-@pks.im>
- In-Reply-To
- <20260302142138.712273-3-jayatheerthkulkarni2005@gmail.com>
On Mon, Mar 02, 2026 at 07:51:37PM +0530, K Jayatheerth wrote:
> The strlen() function returns a size_t
Micronit: missing punctuation.
Show 20 quoted lines
> Storing this in a standard signed int is a bad practice
> that invites overflow vulnerabilities if paths get absurdly long.
>
> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
> ---
> path.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/path.c b/path.c
> index f613d8bbd1..56be5e1726 100644
> --- a/path.c
> +++ b/path.c
> @@ -58,7 +58,7 @@ static void strbuf_cleanup_path(struct strbuf *sb)
>
> static int dir_prefix(const char *buf, const char *dir)
> {
> - int len = strlen(dir);
> + size_t len = strlen(dir);
> return !strncmp(buf, dir, len) &&
> (is_dir_sep(buf[len]) || buf[len] == '\0');Makes sense. What's left out in the commit message is an explanation that this change is safe to do without any further changes. But judging by the diff it's used in contexts where we already expect a `size_t` anyway, so it is.
Patrick