From 392337b3b16cda02af153bd80cd46a7103e9ffba Mon Sep 17 00:00:00 2001 From: Jason Hood Date: Mon, 12 Feb 2018 21:50:43 +1000 Subject: [PATCH] Wrap the cache in a critical section Git's error messages were being truncated. Turns out git used two threads, one writing to the console and one to file. This caused a conflict in `IsConsoleHandle` when the cache was updated. Making it a critical section solves the issue. --- ANSI.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ANSI.c b/ANSI.c index 75e3ca7..f06f145 100644 --- a/ANSI.c +++ b/ANSI.c @@ -3189,6 +3189,8 @@ BOOL IsConsoleHandle( HANDLE h ) { int c; + EnterCriticalSection( &CritSect ); + for (c = 0; c < CACHE; ++c) if (cache[c].h == h) { @@ -3198,7 +3200,9 @@ BOOL IsConsoleHandle( HANDLE h ) do cache[c] = cache[c-1]; while (--c > 0); cache[0] = tc; } - return (cache[0].mode & ENABLE_PROCESSED_OUTPUT); + c = (cache[0].mode & ENABLE_PROCESSED_OUTPUT); + LeaveCriticalSection( &CritSect ); + return c; } while (--c > 0) @@ -3216,7 +3220,11 @@ BOOL IsConsoleHandle( HANDLE h ) cache[0].mode = ENABLE_PROCESSED_OUTPUT; } - return (cache[0].mode & ENABLE_PROCESSED_OUTPUT); + c = (cache[0].mode & ENABLE_PROCESSED_OUTPUT); + + LeaveCriticalSection( &CritSect ); + + return c; } //-----------------------------------------------------------------------------