Clang format it all

This commit is contained in:
Tomer Lev 2022-11-01 19:31:15 +02:00
parent 12494aac45
commit 5cdc6e150e
18 changed files with 323 additions and 313 deletions

View file

@ -23,8 +23,7 @@ do \
fprintf(stderr, "\n"); \ fprintf(stderr, "\n"); \
_exit(1); \ _exit(1); \
} \ } \
} \ } while ( 0 )
while (0)
#endif #endif

View file

@ -26,9 +26,13 @@ public:
*/ */
int FD() const int FD() const
#if ! defined(_MSC_VER) #if ! defined(_MSC_VER)
{ return pipe.ReadFD(); } {
return pipe.ReadFD();
}
#else #else
{ return recvfd; } {
return recvfd;
}
#endif #endif
/** /**

View file

@ -3962,7 +3962,6 @@ ValManager::ValManager()
for ( auto i = 0u; i < PREALLOCATED_INTS; ++i ) for ( auto i = 0u; i < PREALLOCATED_INTS; ++i )
ints[i] = Val::MakeInt(PREALLOCATED_INT_LOWEST + i); ints[i] = Val::MakeInt(PREALLOCATED_INT_LOWEST + i);
} }
const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type) const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type)
@ -3975,9 +3974,7 @@ const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type)
std::pair key{port_num, port_type}; std::pair key{port_num, port_type};
if ( ports.find(key) == ports.end() ) if ( ports.find(key) == ports.end() )
{
ports[key] = IntrusivePtr{AdoptRef{}, new PortVal(PortVal::Mask(port_num, port_type))}; ports[key] = IntrusivePtr{AdoptRef{}, new PortVal(PortVal::Mask(port_num, port_type))};
}
return ports[key]; return ports[key];
} }

View file

@ -62,7 +62,8 @@ bool IPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet)
return false; return false;
} }
ip_hdr = std::make_shared<IP_Hdr>((const struct ip6_hdr*)data, false, static_cast<int>(len)); packet->ip_hdr = std::make_shared<IP_Hdr>((const struct ip6_hdr*)data, false,
static_cast<int>(len));
packet->l3_proto = L3_IPV6; packet->l3_proto = L3_IPV6;
} }
else else

View file

@ -1,18 +1,21 @@
#include <mutex>
#include "Plugin.h" #include "Plugin.h"
#include "zeek/Func.h" #include <mutex>
#include "zeek/Event.h"
#include "zeek/Conn.h" #include "zeek/Conn.h"
#include "zeek/Desc.h" #include "zeek/Desc.h"
#include "zeek/threading/Formatter.h" #include "zeek/Event.h"
#include "zeek/Func.h"
#include "zeek/RunState.h" #include "zeek/RunState.h"
#include "zeek/threading/Formatter.h"
#include "statistics.bif.h" #include "statistics.bif.h"
namespace zeek::plugin::statistics { Plugin plugin; } namespace zeek::plugin::statistics
{
Plugin plugin;
}
using namespace zeek::plugin::statistics; using namespace zeek::plugin::statistics;

View file

@ -1,12 +1,14 @@
#pragma once #pragma once
#include <unordered_map>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <unordered_map>
#include "zeek/plugin/Plugin.h" #include "zeek/plugin/Plugin.h"
namespace zeek::plugin::statistics { namespace zeek::plugin::statistics
{
class Plugin : public zeek::plugin::Plugin class Plugin : public zeek::plugin::Plugin
{ {
@ -22,7 +24,6 @@ public:
private: private:
std::unordered_map<const char*, int> m_eventNameCounters; std::unordered_map<const char*, int> m_eventNameCounters;
std::mutex m_lock; std::mutex m_lock;
}; };
extern Plugin plugin; extern Plugin plugin;

View file

@ -995,12 +995,14 @@ std::optional<SupervisedNode> Stem::Poll()
node_pollfd_indices[name] = pfd_idx; node_pollfd_indices[name] = pfd_idx;
if ( node.stdout_pipe.pipe ) if ( node.stdout_pipe.pipe )
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(node.stdout_pipe.pipe->ReadFD()), POLLIN, 0}; pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(node.stdout_pipe.pipe->ReadFD()),
POLLIN, 0};
else else
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(-1), POLLIN, 0}; pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(-1), POLLIN, 0};
if ( node.stderr_pipe.pipe ) if ( node.stderr_pipe.pipe )
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(node.stderr_pipe.pipe->ReadFD()), POLLIN, 0}; pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(node.stderr_pipe.pipe->ReadFD()),
POLLIN, 0};
else else
pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(-1), POLLIN, 0}; pfds[pfd_idx++] = {static_cast<decltype(pollfd::fd)>(-1), POLLIN, 0};
} }

View file

@ -50,7 +50,8 @@ void BasicThread::SetOSName(const char* arg_name)
{ {
// Do it only if libc++ supports pthread_t. // Do it only if libc++ supports pthread_t.
if constexpr ( std::is_same<std::thread::native_handle_type, pthread_t>::value ) if constexpr ( std::is_same<std::thread::native_handle_type, pthread_t>::value )
zeek::util::detail::set_thread_name(arg_name, reinterpret_cast<pthread_t>(thread.native_handle())); zeek::util::detail::set_thread_name(arg_name,
reinterpret_cast<pthread_t>(thread.native_handle()));
} }
const char* BasicThread::Fmt(const char* format, ...) const char* BasicThread::Fmt(const char* format, ...)

View file

@ -40,9 +40,9 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <iostream> #include <iostream>
#include <random>
#include <string> #include <string>
#include <vector> #include <vector>
#include <random>
#include "zeek/3rdparty/ConvertUTF.h" #include "zeek/3rdparty/ConvertUTF.h"
#include "zeek/3rdparty/doctest.h" #include "zeek/3rdparty/doctest.h"
@ -662,7 +662,8 @@ TEST_CASE("util normalize_path")
string normalize_path(std::string_view path) string normalize_path(std::string_view path)
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
if (0 == path.compare(zeek::detail::ScannedFile::canonical_stdin_path)) { if ( 0 == path.compare(zeek::detail::ScannedFile::canonical_stdin_path) )
{
return string(path); return string(path);
} }
// "//" interferes with std::weakly_canonical // "//" interferes with std::weakly_canonical
@ -1805,14 +1806,11 @@ FILE* open_file(const string& path, const string& mode)
return rval; return rval;
} }
TEST_CASE("util path ops") TEST_CASE("util path ops"){
{
#ifdef _MSC_VER #ifdef _MSC_VER
// TODO: adapt these tests to Windows paths // TODO: adapt these tests to Windows paths
#else #else
SUBCASE("SafeDirname") SUBCASE("SafeDirname"){SafeDirname d("/this/is/a/path", false);
{
SafeDirname d("/this/is/a/path", false);
CHECK(d.result == "/this/is/a"); CHECK(d.result == "/this/is/a");
SafeDirname d2("invalid", false); SafeDirname d2("invalid", false);
@ -1835,7 +1833,8 @@ TEST_CASE("util path ops")
#endif #endif
} }
SafeDirname::SafeDirname(const char* path, bool error_aborts) : SafePathOp() SafeDirname::SafeDirname(const char* path, bool error_aborts)
: SafePathOp()
{ {
DoFunc(path ? path : "", error_aborts); DoFunc(path ? path : "", error_aborts);
} }

View file

@ -16,7 +16,6 @@
#include <libgen.h> #include <libgen.h>
#include <unistd.h> #include <unistd.h>
#include <array> #include <array>
#include <cinttypes> #include <cinttypes>
#include <cstdarg> #include <cstdarg>
@ -82,13 +81,19 @@ extern "C"
#ifdef _MSC_VER #ifdef _MSC_VER
#include <pthread.h> #include <pthread.h>
#include <filesystem> #include <filesystem>
namespace zeek { namespace filesystem = std::filesystem; } namespace zeek
{
namespace filesystem = std::filesystem;
}
inline constexpr std::string_view path_list_separator = ";"; inline constexpr std::string_view path_list_separator = ";";
#else #else
// Expose ghc::filesystem as zeek::filesystem until we can // Expose ghc::filesystem as zeek::filesystem until we can
// switch to std::filesystem on all platforms. // switch to std::filesystem on all platforms.
#include "zeek/3rdparty/ghc/filesystem.hpp" #include "zeek/3rdparty/ghc/filesystem.hpp"
namespace zeek { namespace filesystem = ghc::filesystem; } namespace zeek
{
namespace filesystem = ghc::filesystem;
}
inline constexpr std::string_view path_list_separator = ":"; inline constexpr std::string_view path_list_separator = ":";
#endif #endif

View file

@ -1,7 +1,5 @@
// See the file "COPYING" in the main distribution directory for copyright. // See the file "COPYING" in the main distribution directory for copyright.
#include <unistd.h>
#include "zeek/zeek-setup.h" #include "zeek/zeek-setup.h"
#include "zeek/zeek-config.h" #include "zeek/zeek-config.h"
@ -10,6 +8,7 @@
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include <csignal> #include <csignal>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
@ -978,8 +977,8 @@ SetupResult setup(int argc, char** argv, Options* zopts)
} }
if ( dns_type != DNS_PRIME ) if ( dns_type != DNS_PRIME )
run_state::detail::init_run(options.interface, options.pcap_file, run_state::detail::init_run(options.interface, options.pcap_file, options.pcap_output_file,
options.pcap_output_file, options.use_watchdog); options.use_watchdog);
if ( ! g_policy_debug ) if ( ! g_policy_debug )
{ {
@ -1107,8 +1106,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
packet_mgr->DumpDebug(); packet_mgr->DumpDebug();
analyzer_mgr->DumpDebug(); analyzer_mgr->DumpDebug();
run_state::detail::have_pending_timers = ! run_state::reading_traces && run_state::detail::have_pending_timers = ! run_state::reading_traces && timer_mgr->Size() > 0;
timer_mgr->Size() > 0;
return {0, std::move(options)}; return {0, std::move(options)};
} }