Skip to content

Commit 2121a76

Browse files
pks-tgitster
authored andcommitted
git-compat-util: introduce macros to disable "-Wsign-compare" warnings
When compiling with DEVELOPER=YesPlease, we explicitly disable the "-Wsign-compare" warning. This is mostly because our code base is full of cases where we don't bother at all whether something should be signed or unsigned, and enabling the warning would thus cause tons of warnings to pop up. Unfortunately, disabling this warning also masks real issues. There have been multiple CVEs in the Git project that would have been flagged by this warning (e.g. CVE-2022-39260, CVE-2022-41903 and several fixes in the vicinity of these CVEs). Furthermore, the final audit report by X41 D-Sec, who are the ones who have discovered some of the CVEs, hinted that it might be a good idea to become more strict in this context. Now simply enabling the warning globally does not fly due to the stated reason above that we simply have too many sites where we use the wrong integer types. Instead, introduce a new set of macros that allow us to mark a file as being free of warnings with "-Wsign-compare". The mechanism is similar to what we do with `USE_THE_REPOSITORY_VARIABLE`: every file that is not marked with `DISABLE_SIGN_COMPARE_WARNINGS` will be compiled with those warnings enabled. These new markings will be wired up in the subsequent commits. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e66fd72 commit 2121a76

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

git-compat-util.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ struct strbuf;
4444
#define GIT_GNUC_PREREQ(maj, min) 0
4545
#endif
4646

47+
#if defined(__GNUC__) || defined(__clang__)
48+
# define PRAGMA(pragma) _Pragma(#pragma)
49+
# define DISABLE_WARNING(warning) PRAGMA(GCC diagnostic ignored #warning)
50+
#else
51+
# define DISABLE_WARNING(warning)
52+
#endif
53+
54+
#ifdef DISABLE_SIGN_COMPARE_WARNINGS
55+
DISABLE_WARNING(-Wsign-compare)
56+
#endif
4757

4858
#ifndef FLEX_ARRAY
4959
/*

0 commit comments

Comments
 (0)