diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2017-05-04 15:55:29 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-08 12:18:19 +0900 |
commit | 3057da5ad51b3256a6f6b94d034e6a5571ce5ece (patch) | |
tree | 53ff345ff374d3f89ec6d534e18ba89da9c6dbbf /compat | |
parent | 1a845a2c88e5b72acce33c9719ec36fcd0f9c877 (diff) | |
download | git-3057da5ad51b3256a6f6b94d034e6a5571ce5ece.tar.gz |
winansi: avoid use of uninitialized value
To initialize the foreground color attributes of "plain text", our ANSI
emulation tries to infer them from the currently attached console while
running the is_console() function. This function first tries to detect any
console attached to stdout, then it is called with stderr.
If neither stdout nor stderr has any console attached, it does not
actually matter what we use for "plain text" attributes, as we never need
to output any text to any console in that case.
However, after working on stdout and stderr, is_console() is called with
stdin, and it still tries to initialize the "plain text" attributes if
they had not been initialized earlier. In this case, we cannot detect any
attributes, and we used an uninitialized value for them.
Naturally, Coverity complained about this use case because it could not
reason about the code deeply enough to figure out that we do not even use
those attributes in that case.
Let's just initialize the value to 0 in that case, both to avoid future
Coverity reports, and to help catch future regressions in case anybody
changes the order of the is_console() calls (which would make the text
black on black).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat')
-rw-r--r-- | compat/winansi.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/compat/winansi.c b/compat/winansi.c index 793420f9d0..a551de90eb 100644 --- a/compat/winansi.c +++ b/compat/winansi.c @@ -105,6 +105,13 @@ static int is_console(int fd) if (!fd) { if (!GetConsoleMode(hcon, &mode)) return 0; + /* + * This code path is only reached if there is no console + * attached to stdout/stderr, i.e. we will not need to output + * any text to any console, therefore we might just as well + * use black as foreground color. + */ + sbi.wAttributes = 0; } else if (!GetConsoleScreenBufferInfo(hcon, &sbi)) return 0; |