Johannes Sixt <j...@kdbg.org> writes:

> We do not want to have it for *all* cases, where we return -1 - pos, but
> only for those cases, where the result was actually encoded by
> index_pos_to_insert_pos().

Yup, I agree with you that decoder should be fed only the data
emitted by the encoder.

But shouldn't the code that yielded 'pos' that later gets decoded by
computing "-1 -pos" without using the encoding helper be corrected
to use the encoder instead?  After all, the primary purpose of
inventing the encoder was to catch the arith overflow, wasn't it?

> That excludes all cases where the argument is
> derived from index_name_pos(), and leaves just...
>
>> --- a/rerere.c
>> +++ b/rerere.c
>> @@ -154,7 +154,7 @@ static struct rerere_dir *find_rerere_dir(const char 
>> *hex)
>>              rr_dir->status = NULL;
>>              rr_dir->status_nr = 0;
>>              rr_dir->status_alloc = 0;
>> -            pos = -1 - pos;
>> +            pos = insert_pos_to_index_pos(pos);
>
> ... this one...
>
>>  
>>              /* Make sure the array is big enough ... */
>>              ALLOC_GROW(rerere_dir, rerere_dir_nr + 1, rerere_dir_alloc);
>> diff --git a/sha1-name.c b/sha1-name.c
>> index 49855ad24f..bee7ce39ee 100644
>> --- a/sha1-name.c
>> +++ b/sha1-name.c
>> @@ -98,7 +98,7 @@ static void find_short_object_filename(struct 
>> disambiguate_state *ds)
>>              loose_objects = odb_loose_cache(odb, &ds->bin_pfx);
>>              pos = oid_array_lookup(loose_objects, &ds->bin_pfx);
>>              if (pos < 0)
>> -                    pos = -1 - pos;
>> +                    pos = insert_pos_to_index_pos(pos);
>
> ... and this one.
>
>>              while (!ds->ambiguous && pos < loose_objects->nr) {
>>                      const struct object_id *oid;
>>                      oid = loose_objects->oid + pos;
>
> -- Hannes

Reply via email to