git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/4] object-file: fix a unpack_loose_header() regression in 3b6a8db3b03

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 22, 2022, 08:21 UTC
Message-ID
<220422.86levx5xuc.gmgdl@evledraar.gmail.com>
In-Reply-To
<xmqqa6cedpt3.fsf@gitster.g>
On Thu, Apr 21 2022, Junio C Hamano wrote:
Show 17 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> -	if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
>> -				NULL) < 0) {
>> +	switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
>> +				    NULL)) {
>> +	case ULHR_OK:
>> +		break;
>> +	case ULHR_BAD:
>> +	case ULHR_TOO_LONG:
>>  		error(_("unable to unpack header of %s"), path);
>>  		goto out;
>>  	}
>
> Sigh, well spotted.  This is why I hate the application of "enum is
> better, let's rewrite the 'negative is error, 0 is good' with it"
> and other dogmatic "clean-up" that touch everywhere in the codebase.

While this is squarely my fault, I'm FWIW not as dogmatic on that point as you think. I initially made a new error state a -2, and got feedback on the series that that was too magical, then ended up turning it into an enum and missed this callsite.

I think it's less that enums are bad in this case, as it's probably sensible to consistently use negative values for error states.

Show 10 quoted lines
> Now because it is ULHR_OK or everything else that is an error, I think
> the fix should be
>
> 	if (unpack_loose_header(...) != ULHR_OK) {
> 		error(...);
> 		goto out;
> 	}
>
> It would also be much closer in spirit to the original code before
> the "enum" change broke it.

We have two other callers of the API using the exhaustive enumeration pattern, so by doing this we'd have the compiler miss this callsite if another label is added.

It could be refactored etc., but I think this change as-is is the most minimal & least invasive. I.e. it just adjusts this one caller to match the other ones, we could also refactor the interface & pattern we use to call it.

But if we're doing that I don't see the benefit of doing it for just one caller, and if we're doing it for all of them surely that's better as some follow-up cleanup...

Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 20 in “Fix issues and a regression noted by valgrind”
  1. 0/4 Fix issues and a regression noted by valgrindÆvar Arnfjörð Bjarmason, Apr 21, 2022
  2. 1/4 tests: make RUNTIME_PREFIX compatible with --valgrindÆvar Arnfjörð Bjarmason, Apr 21, 2022
  3. Junio C HamanoApr 21, 2022
  4. 2/4 log test: skip a failing mkstemp() test under valgrindÆvar Arnfjörð Bjarmason, Apr 21, 2022
  5. 3/4 commit-graph.c: don't assume that stat() succeedsÆvar Arnfjörð Bjarmason, Apr 21, 2022
  6. Junio C HamanoApr 21, 2022
  7. 4/4 object-file: fix a unpack_loose_header() regression in 3b6a8db3b03Ævar Arnfjörð Bjarmason, Apr 21, 2022
  8. Junio C HamanoApr 21, 2022
  9. Ævar Arnfjörð BjarmasonApr 22, 2022
  10. 0/4 test fixes around valgrindJunio C Hamano, May 12, 2022
  11. 1/4 tests: using custom GIT_EXEC_PATH breaks --valgrind testsJunio C Hamano, May 12, 2022
  12. 2/4 log test: skip a failing mkstemp() test under valgrindJunio C Hamano, May 12, 2022
  13. 4/4 object-file: fix a unpack_loose_header() regression in 3b6a8db3b03Junio C Hamano, May 12, 2022
  14. Junio C HamanoMay 12, 2022
  15. Derrick StoleeMay 16, 2022
  16. 0/2 Alternate ab/valgrind-fixes fix-upÆvar Arnfjörð Bjarmason, May 19, 2022
  17. 1/2 object-file API: fix obscure unpack_loose_header() returnÆvar Arnfjörð Bjarmason, May 19, 2022
  18. 2/2 object-file API: have unpack_loose_header() return "int" againÆvar Arnfjörð Bjarmason, May 19, 2022
  19. Junio C HamanoMay 20, 2022
  20. 3/4 commit-graph.c: don't assume that stat() succeedsJunio C Hamano, May 12, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.