diff options
author | Zulkarnine Mahmud <zulkarnine2076@gmail.com> | 2017-07-15 08:44:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-15 08:44:18 (GMT) |
commit | a6b146dfddb9462b901b1eb45ee0d6d761f021bf (patch) | |
tree | 8fe20a91f97039b8f6a485cb4a94df9d5daa34e7 /googletest | |
parent | 6a75e3c169d2ab0fb1ff096b7922375f08d3359c (diff) | |
download | googletest-a6b146dfddb9462b901b1eb45ee0d6d761f021bf.zip googletest-a6b146dfddb9462b901b1eb45ee0d6d761f021bf.tar.gz googletest-a6b146dfddb9462b901b1eb45ee0d6d761f021bf.tar.bz2 |
Fix assumption for foreground bit offset
Diffstat (limited to 'googletest')
-rw-r--r-- | googletest/src/gtest.cc | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 30e0094..9bcb173 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2895,7 +2895,7 @@ WORD GetColorAttribute(GTestColor color) { } int GetBgOffset(WORD background_mask) { - if (background_mask == 0) return 0; //let's not fall into infinite loop + if (background_mask == 0) return 0; int bitOffset = 0; while((background_mask & 1) == 0) { @@ -2905,6 +2905,16 @@ int GetBgOffset(WORD background_mask) { return bitOffset; } +int GetFgOffset(WORD foreground_mask) { + if (foreground_mask == 0) return 0; + + int bitOffset = 0; + while((foreground_mask & 1) == 0) { + foreground_mask >>= 1; + ++bitOffset; + } + return bitOffset; +} WORD GetNewColor(GTestColor color, WORD old_color_attrs) { // Let's reuse the BG static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY; @@ -2912,9 +2922,12 @@ WORD GetNewColor(GTestColor color, WORD old_color_attrs) { const WORD existing_bg = old_color_attrs & background_mask; WORD new_color = GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY; - static const int bg_bitOffset = GetBgOffset(background_mask); //it does not change + static const int bg_bitOffset = GetBgOffset(background_mask); + static const int fg_bitOffset = GetFgOffset(foreground_mask); - if (((new_color & background_mask) >> bg_bitOffset) == (new_color & foreground_mask)) new_color ^= FOREGROUND_INTENSITY; //revert intensity + if (((new_color & background_mask) >> bg_bitOffset) == ((new_color & foreground_mask) >> fg_bitOffset)) { + new_color ^= FOREGROUND_INTENSITY; //invert intensity + } return new_color; } |