Skip to content

Commit 3ce3ffb

Browse files
apelissegitster
authored andcommitted
fix clang -Wtautological-compare with unsigned enum
Create a GREP_HEADER_FIELD_MIN so we can check that the field value is sane and silence the clang warning. Clang warning happens because the enum is unsigned (this is implementation-defined, and there is no negative fields) and the check is then tautological. Signed-off-by: Antoine Pelisse <[email protected]> Signed-off-by: John Keeping <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ded807 commit 3ce3ffb

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

grep.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ static struct grep_expr *prep_header_patterns(struct grep_opt *opt)
625625
for (p = opt->header_list; p; p = p->next) {
626626
if (p->token != GREP_PATTERN_HEAD)
627627
die("bug: a non-header pattern in grep header list.");
628-
if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)
628+
if (p->field < GREP_HEADER_FIELD_MIN ||
629+
GREP_HEADER_FIELD_MAX <= p->field)
629630
die("bug: unknown header field %d", p->field);
630631
compile_regexp(p, opt);
631632
}

grep.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ enum grep_context {
2828
};
2929

3030
enum grep_header_field {
31-
GREP_HEADER_AUTHOR = 0,
31+
GREP_HEADER_FIELD_MIN = 0,
32+
GREP_HEADER_AUTHOR = GREP_HEADER_FIELD_MIN,
3233
GREP_HEADER_COMMITTER,
3334
GREP_HEADER_REFLOG,
3435

0 commit comments

Comments
 (0)