This is an archive of the discontinued LLVM Phabricator instance.

Fix some crashes and deadlocks in FormatAnsiTerminalCodes
ClosedPublic

Authored by teemperor on Jul 13 2018, 10:28 AM.

Details

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).

Diff Detail

Event Timeline

teemperor created this revision.Jul 13 2018, 10:28 AM
labath accepted this revision.Jul 16 2018, 4:14 AM
labath added a subscriber: labath.

This looks straight-forward enough.

unittests/Utility/AnsiTerminalTest.cpp
18

I would suggest getting rid of the temporary format variable. That way, if this assertion fails, the error message will immediately tell you what the failing command was.
(you can also use EXPECT_EQ here as operator== will do the right thing when one of the arguments is a std::string)

This revision is now accepted and ready to land.Jul 16 2018, 4:14 AM
teemperor updated this revision to Diff 155706.Jul 16 2018, 9:42 AM
  • Removed temp string variables.
This revision was automatically updated to reflect the committed changes.