Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some crashes and deadlocks in FormatAnsiTerminalCodes
Summary: This patch fixes a few problems with the FormatAnsiTerminalCodes function: * It does an infinite loop on an unknown color value. * It crashes when the color value is at the end of the string. * It deletes the first character behind the color token. Also added a few tests that reproduce those problems (and test some other corner cases). Reviewers: davide, labath Reviewed By: labath Subscribers: labath, lldb-commits, mgorny Differential Revision: https://reviews.llvm.org/D49307 llvm-svn: 337189
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//===-- AnsiTerminalTest.cpp ------------------------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include "lldb/Utility/AnsiTerminal.h" | ||
|
||
using namespace lldb_utility; | ||
|
||
TEST(AnsiTerminal, Empty) { EXPECT_EQ("", ansi::FormatAnsiTerminalCodes("")); } | ||
|
||
TEST(AnsiTerminal, WhiteSpace) { | ||
EXPECT_EQ(" ", ansi::FormatAnsiTerminalCodes(" ")); | ||
} | ||
|
||
TEST(AnsiTerminal, AtEnd) { | ||
EXPECT_EQ("abc\x1B[30m", | ||
ansi::FormatAnsiTerminalCodes("abc${ansi.fg.black}")); | ||
} | ||
|
||
TEST(AnsiTerminal, AtStart) { | ||
EXPECT_EQ("\x1B[30mabc", | ||
ansi::FormatAnsiTerminalCodes("${ansi.fg.black}abc")); | ||
} | ||
|
||
TEST(AnsiTerminal, KnownPrefix) { | ||
EXPECT_EQ("${ansi.fg.redish}abc", | ||
ansi::FormatAnsiTerminalCodes("${ansi.fg.redish}abc")); | ||
} | ||
|
||
TEST(AnsiTerminal, Unknown) { | ||
EXPECT_EQ("${ansi.fg.foo}abc", | ||
ansi::FormatAnsiTerminalCodes("${ansi.fg.foo}abc")); | ||
} | ||
|
||
TEST(AnsiTerminal, Incomplete) { | ||
EXPECT_EQ("abc${ansi.", ansi::FormatAnsiTerminalCodes("abc${ansi.")); | ||
} | ||
|
||
TEST(AnsiTerminal, Twice) { | ||
EXPECT_EQ("\x1B[30m\x1B[31mabc", | ||
ansi::FormatAnsiTerminalCodes("${ansi.fg.black}${ansi.fg.red}abc")); | ||
} | ||
|
||
TEST(AnsiTerminal, Basic) { | ||
EXPECT_EQ( | ||
"abc\x1B[31mabc\x1B[0mabc", | ||
ansi::FormatAnsiTerminalCodes("abc${ansi.fg.red}abc${ansi.normal}abc")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_lldb_unittest(UtilityTests | ||
AnsiTerminalTest.cpp | ||
ArgsTest.cpp | ||
OptionsWithRawTest.cpp | ||
ArchSpecTest.cpp | ||
|