Re: [PATCH v3 3/4] string-list: change "string_list_find_insert_index" return type to "size_t"
- From
Jeff King <peff@peff.net>
- Date
- Oct 9, 2025, 06:03 UTC
- Message-ID
- <20251009060311.GE1614343@coredump.intra.peff.net>
- In-Reply-To
- <aONiiGlaUfT5cJpd@ArchLinux>
On Mon, Oct 06, 2025 at 02:32:40PM +0800, shejialuo wrote:
Show 9 quoted lines
> @@ -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