From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com> To: Junio C Hamano <gitster@pobox.com> Cc: git@vger.kernel.org, Derrick Stolee <derrickstolee@github.com>, Johannes Schindelin <Johannes.Schindelin@gmx.de>, Hans Jerry Illikainen <hji@dyntopia.com> Subject: Re: [PATCH 4/4] object-file: fix a unpack_loose_header() regression in 3b6a8db3b03 Date: Fri, 22 Apr 2022 10:21:50 +0200 [thread overview] Message-ID: <220422.86levx5xuc.gmgdl@evledraar.gmail.com> (raw) In-Reply-To: <xmqqa6cedpt3.fsf@gitster.g> On Thu, Apr 21 2022, Junio C Hamano wrote: > Æ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. > 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...
next prev parent reply other threads:[~2022-04-22 8:26 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-21 20:14 [PATCH 0/4] Fix issues and a regression noted by valgrind Ævar Arnfjörð Bjarmason 2022-04-21 20:14 ` [PATCH 1/4] tests: make RUNTIME_PREFIX compatible with --valgrind Ævar Arnfjörð Bjarmason 2022-04-21 22:22 ` Junio C Hamano 2022-04-21 20:14 ` [PATCH 2/4] log test: skip a failing mkstemp() test under valgrind Ævar Arnfjörð Bjarmason 2022-04-21 20:14 ` [PATCH 3/4] commit-graph.c: don't assume that stat() succeeds Ævar Arnfjörð Bjarmason 2022-04-21 22:29 ` Junio C Hamano 2022-04-21 20:14 ` [PATCH 4/4] object-file: fix a unpack_loose_header() regression in 3b6a8db3b03 Ævar Arnfjörð Bjarmason 2022-04-21 22:39 ` Junio C Hamano 2022-04-22 8:21 ` Ævar Arnfjörð Bjarmason [this message] 2022-05-12 22:32 ` [PATCH v2 0/4] test fixes around valgrind Junio C Hamano 2022-05-12 22:32 ` [PATCH v2 1/4] tests: using custom GIT_EXEC_PATH breaks --valgrind tests Junio C Hamano 2022-05-12 22:32 ` [PATCH v2 2/4] log test: skip a failing mkstemp() test under valgrind Junio C Hamano 2022-05-12 22:32 ` [PATCH v2 3/4] commit-graph.c: don't assume that stat() succeeds Junio C Hamano 2022-05-12 22:32 ` [PATCH v2 4/4] object-file: fix a unpack_loose_header() regression in 3b6a8db3b03 Junio C Hamano 2022-05-12 23:39 ` Junio C Hamano 2022-05-16 14:59 ` Derrick Stolee 2022-05-19 20:09 ` [RFC PATCH 0/2] Alternate ab/valgrind-fixes fix-up Ævar Arnfjörð Bjarmason 2022-05-19 20:09 ` [RFC PATCH 1/2] object-file API: fix obscure unpack_loose_header() return Ævar Arnfjörð Bjarmason 2022-05-19 20:09 ` [RFC PATCH 2/2] object-file API: have unpack_loose_header() return "int" again Ævar Arnfjörð Bjarmason 2022-05-20 4:27 ` Junio C Hamano
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=220422.86levx5xuc.gmgdl@evledraar.gmail.com \ --to=avarab@gmail.com \ --cc=Johannes.Schindelin@gmx.de \ --cc=derrickstolee@github.com \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=hji@dyntopia.com \ --subject='Re: [PATCH 4/4] object-file: fix a unpack_loose_header() regression in 3b6a8db3b03' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://80x24.org/mirrors/git.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).