From: Jeff King Date: Thu, 09 Oct 2025 06:03:11 GMT Subject: Re: [PATCH v3 3/4] string-list: change "string_list_find_insert_index" return type to "size_t" Message-ID: <20251009060311.GE1614343@coredump.intra.peff.net> In-Reply-To: On Mon, Oct 06, 2025 at 02:32:40PM +0800, shejialuo wrote: > @@ -266,7 +265,7 @@ static struct string_list_item *lookup_prefix(struct string_list *map, > * overlong key would be inserted, which must come after the > * real location of the key if one exists. > */ > - while (0 <= --i && i < map->nr) { > + while (i-- && i < map->nr) { > int cmp = strncasecmp(map->items[i].string, string, len); > if (cmp < 0) > /* BTW, Coverity complains about this line, because "i--" will wrap when "i" is 0. I think that's OK for our purposes, because we will break out of the loop on that condition (because it's a post-increment), and we never look at "i" outside of the loop after that. So I don't think it's worth changing even to try to shut Coverity up, but it's an interesting data point in how subtle the signed/unsigned conversions can be. -Peff