]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsck.c: call parse_msg_type() early in fsck_set_msg_type()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sun, 28 Mar 2021 13:15:42 +0000 (15:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Mar 2021 02:03:10 +0000 (19:03 -0700)
There's no reason to defer the calling of parse_msg_type() until after
we've checked if the "id < 0". This is not a hot codepath, and
parse_msg_type() itself may die on invalid input.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsck.c

diff --git a/fsck.c b/fsck.c
index c5a81e4ff05a0558e3e135f479bf298c3b46ede6..80365e62842b175496defaeeabc2833df73a339f 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options,
                       const char *msg_id_str, const char *msg_type_str)
 {
        int msg_id = parse_msg_id(msg_id_str);
-       enum fsck_msg_type msg_type;
+       enum fsck_msg_type msg_type = parse_msg_type(msg_type_str);
 
        if (msg_id < 0)
                die("Unhandled message id: %s", msg_id_str);
-       msg_type = parse_msg_type(msg_type_str);
 
        if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
                die("Cannot demote %s to %s", msg_id_str, msg_type_str);