Re: [PATCH v2 03/10] mailmap: remove email copy and length limitation
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 9, 2013, 17:56 UTC
- Message-ID
- <7vbocy6y0n.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <7vfw2a6yh5.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 20 quoted lines
> Antoine Pelisse <apelisse@gmail.com> writes:
>
>>> +static struct string_list_item *lookup_prefix(struct string_list *map,
>>> + const char *string, size_t len)
>>> +{
>>> + int i = string_list_find_insert_index(map, string, 1);
>>> + if (i < 0) {
>>> + /* exact match */
>>> + i = -1 - i;
>>> + /* does it match exactly? */
>>> + if (!map->items[i].string[len])
>>> + return &map->items[i];
>>
>> I'm not sure the condition above is necessary, as I don't see why an
>> exact match would not be an exact match.
>
> You have a overlong string "ABCDEFG", but you only want to look for
> "ABCDEF", i.e. len=6. The string_list happens to have an existing
> string "ABCDEFG". The insert-index function will report an exact
> match, but that does not mean you found what you are looking for. To put it another way, we can further clarify the situation by rewording the comment "Does it match exactly?", perhaps like this
if (i < 0) {
/* exact match */
i = -1 - i;
if (!string[len])
return &map->items[i];
/*
* It matched exactly even to the cruft at the end
* of the string, so it is not really a match.
*/
}