Skip to content

Commit

Permalink
Fix infinite loop in compact reporter printer
Browse files Browse the repository at this point in the history
Also simplify some variables with auto deduction.
  • Loading branch information
sfranzen committed Aug 6, 2019
1 parent cf55cfd commit 3d9e7db
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions include/reporters/catch_reporter_compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,24 +209,25 @@ class AssertionPrinter {
if (itMessage == messages.end())
return;

// using messages.end() directly yields (or auto) compilation error:
std::vector<MessageInfo>::const_iterator itEnd = messages.end();
const std::size_t N = static_cast<std::size_t>(std::distance(itMessage, itEnd));
const auto itEnd = messages.cend();
const auto N = static_cast<std::size_t>(std::distance(itMessage, itEnd));

{
Colour colourGuard(colour);
stream << " with " << pluralise(N, "message") << ':';
}

for (; itMessage != itEnd; ) {
while (itMessage != itEnd) {
// If this assertion is a warning ignore any INFO messages
if (printInfoMessages || itMessage->type != ResultWas::Info) {
stream << " '" << itMessage->message << '\'';
if (++itMessage != itEnd) {
printMessage();
if (itMessage != itEnd) {
Colour colourGuard(dimColour());
stream << " and";
}
continue;
}
++itMessage;
}
}

Expand Down

0 comments on commit 3d9e7db

Please sign in to comment.