Fix GCC builds and string output for Broker errors

This commit is contained in:
Dominik Charousset 2021-12-21 11:02:26 +01:00
parent 56f30b500a
commit da2a5ef455
3 changed files with 54 additions and 2 deletions

@ -1 +1 @@
Subproject commit ce321c0a90f1d4176796c996fd27fe69ea520316
Subproject commit 0b2691392f335d409781257f210c7b1681530c59

View file

@ -28,6 +28,57 @@
using namespace std;
namespace {
void print_escaped(std::string& buf, std::string_view str)
{
buf.push_back('"');
for ( auto c : str )
{
switch ( c )
{
default:
buf.push_back(c);
break;
case '\\':
buf.push_back('\\');
buf.push_back('\\');
break;
case '\b':
buf.push_back('\\');
buf.push_back('b');
break;
case '\f':
buf.push_back('\\');
buf.push_back('f');
break;
case '\n':
buf.push_back('\\');
buf.push_back('n');
break;
case '\r':
buf.push_back('\\');
buf.push_back('r');
break;
case '\t':
buf.push_back('\\');
buf.push_back('t');
break;
case '\v':
buf.push_back('\\');
buf.push_back('v');
break;
case '"':
buf.push_back('\\');
buf.push_back('"');
break;
}
}
buf.push_back('"');
}
} // namespace
namespace zeek::Broker
{
@ -1658,7 +1709,7 @@ void Manager::ProcessError(broker::error_view err)
msg += broker::to_string(ctx->network);
msg += ", ";
if ( auto what = err.message() )
msg += *what;
print_escaped(msg, *what);
else
msg += R"_("")_";
msg += ')';

View file

@ -5,6 +5,7 @@
#include <broker/data.hh>
#include <openssl/sha.h>
#include <cassert>
#include <cstring>
#include <limits>
#include "zeek/digest.h"