Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal/catch_console_colour.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-01-29 23:12:40 +0100
committerMartin Hořeňovský2022-01-29 23:12:55 +0100
commitefb54926eec28900e020131930b35116075f6f84 (patch)
treee1079538fdfdf283bbaa23ecac21bf46e79cf4be /src/catch2/internal/catch_console_colour.cpp
parent7a2f9f4633412b57e3e60e710a1a0e1ef33ca122 (diff)
downloadcatch3-efb54926eec28900e020131930b35116075f6f84.tar.gz
Don't cache stdout handle in Windows console colour impl
The cached handle would become invalid if some other code, say a user-provided test code, redirects stdout through `freopen` or `_dup2`, which would then cause AppVerifier to complain. Fixes #2345
Diffstat (limited to 'src/catch2/internal/catch_console_colour.cpp')
-rw-r--r--src/catch2/internal/catch_console_colour.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/catch2/internal/catch_console_colour.cpp b/src/catch2/internal/catch_console_colour.cpp
index 069c5fbe..b3e4934e 100644
--- a/src/catch2/internal/catch_console_colour.cpp
+++ b/src/catch2/internal/catch_console_colour.cpp
@@ -59,10 +59,10 @@ namespace {
class Win32ColourImpl : public IColourImpl {
public:
- Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
- {
+ Win32ColourImpl() {
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
- GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
+ GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ),
+ &csbiInfo );
originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
}
@@ -93,9 +93,10 @@ namespace {
private:
void setTextAttribute( WORD _textAttribute ) {
- SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
+ SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),
+ _textAttribute |
+ originalBackgroundAttributes );
}
- HANDLE stdoutHandle;
WORD originalForegroundAttributes;
WORD originalBackgroundAttributes;
};