Am 02.05.2017 um 18:01 schrieb Johannes Schindelin:
When stdout is not connected to a Win32 console, we incorrectly used an uninitialized value for the "plain" character attributes. Detected by Coverity. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- compat/winansi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compat/winansi.c b/compat/winansi.c index 793420f9d0d..fd6910746c8 100644 --- a/compat/winansi.c +++ b/compat/winansi.c @@ -105,6 +105,8 @@ static int is_console(int fd) if (!fd) { if (!GetConsoleMode(hcon, &mode)) return 0; + sbi.wAttributes = FOREGROUND_BLUE | FOREGROUND_GREEN | + FOREGROUND_RED; } else if (!GetConsoleScreenBufferInfo(hcon, &sbi)) return 0;
So is_console is called with fd being 1 (stdout), 2 (stderr) and 0 (stdin), in that order. If the first two calls abort early for some reason we may end up here. The added code is for white text on black background. An alias for that combination, FOREGROUND_ALL, is defined a few lines down; for a minimal fix it's not worth moving it up. attr and plain_attr are both initialized to sbi.wAttributes. That as a bit more complicated than it looked initially. The order of calls is important, "stdout" in the commit message includes stderr as well and it doesn't just affect plain_attr. Would a value of 0 (black text on black background) suffice if only stdin is connected to a console? Colors don't matter if there is nothing to see, right? Anyway, the change makes sense as is, but it took me a while to get it. René