mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Fix clang-tidy findings in the binpac lib code
This commit is contained in:
parent
4ae8bb856d
commit
cd1414ab69
5 changed files with 28 additions and 26 deletions
|
@ -17,7 +17,7 @@ public:
|
||||||
int contract_threshold;
|
int contract_threshold;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum LineBreakStyle {
|
enum LineBreakStyle : uint8_t {
|
||||||
CR_OR_LF, // CR or LF or CRLF
|
CR_OR_LF, // CR or LF or CRLF
|
||||||
STRICT_CRLF, // CR followed by LF
|
STRICT_CRLF, // CR followed by LF
|
||||||
CR_LF_NUL, // CR or LF or CR-LF or CR-NUL
|
CR_LF_NUL, // CR or LF or CR-LF or CR-NUL
|
||||||
|
@ -142,13 +142,13 @@ protected:
|
||||||
LineBreakStyle linebreak_style_default;
|
LineBreakStyle linebreak_style_default;
|
||||||
unsigned char linebreaker_;
|
unsigned char linebreaker_;
|
||||||
|
|
||||||
enum {
|
enum : uint8_t {
|
||||||
UNKNOWN_MODE,
|
UNKNOWN_MODE,
|
||||||
LINE_MODE,
|
LINE_MODE,
|
||||||
FRAME_MODE,
|
FRAME_MODE,
|
||||||
} mode_;
|
} mode_;
|
||||||
|
|
||||||
enum {
|
enum : uint8_t {
|
||||||
CR_OR_LF_0,
|
CR_OR_LF_0,
|
||||||
CR_OR_LF_1,
|
CR_OR_LF_1,
|
||||||
STRICT_CRLF_0,
|
STRICT_CRLF_0,
|
||||||
|
@ -163,7 +163,7 @@ protected:
|
||||||
static Policy policy;
|
static Policy policy;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef FlowBuffer* flow_buffer_t;
|
using flow_buffer_t = FlowBuffer*;
|
||||||
|
|
||||||
} // namespace binpac
|
} // namespace binpac
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#ifndef binpac_bytestring_h
|
#ifndef binpac_bytestring_h
|
||||||
#define binpac_bytestring_h
|
#define binpac_bytestring_h
|
||||||
|
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "binpac.h"
|
#include "binpac.h"
|
||||||
|
@ -16,7 +16,7 @@ class datastring;
|
||||||
template<class T>
|
template<class T>
|
||||||
class const_datastring {
|
class const_datastring {
|
||||||
public:
|
public:
|
||||||
const_datastring() : begin_(0), end_(0) {}
|
const_datastring() : begin_(nullptr), end_(nullptr) {}
|
||||||
|
|
||||||
const_datastring(T const* data, int length) : begin_(data), end_(data + length) {}
|
const_datastring(T const* data, int length) : begin_(data), end_(data + length) {}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ private:
|
||||||
T const* end_;
|
T const* end_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef const_datastring<uint8> const_bytestring;
|
using const_bytestring = const_datastring<uint8>;
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class datastring {
|
class datastring {
|
||||||
|
@ -65,6 +65,9 @@ public:
|
||||||
explicit datastring(const_datastring<T> const& x) { set_const(x.begin(), x.length()); }
|
explicit datastring(const_datastring<T> const& x) { set_const(x.begin(), x.length()); }
|
||||||
|
|
||||||
datastring const& operator=(datastring<T> const& x) {
|
datastring const& operator=(datastring<T> const& x) {
|
||||||
|
if ( this == &x )
|
||||||
|
return *this;
|
||||||
|
|
||||||
BINPAC_ASSERT(! data_);
|
BINPAC_ASSERT(! data_);
|
||||||
set(x.data(), x.length());
|
set(x.data(), x.length());
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -76,7 +79,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
data_ = 0;
|
data_ = nullptr;
|
||||||
length_ = 0;
|
length_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,13 +122,11 @@ private:
|
||||||
int length_;
|
int length_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef datastring<uint8> bytestring;
|
using bytestring = datastring<uint8>;
|
||||||
|
|
||||||
inline const char* c_str(bytestring const& s) { return (const char*)s.begin(); }
|
inline const char* c_str(bytestring const& s) { return (const char*)s.begin(); }
|
||||||
|
|
||||||
inline std::string std_str(const_bytestring const& s) {
|
inline std::string std_str(const_bytestring const& s) { return {(const char*)s.begin(), (const char*)s.end()}; }
|
||||||
return std::string((const char*)s.begin(), (const char*)s.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(bytestring const& s1, const char* s2) { return strcmp(c_str(s1), s2) == 0; }
|
inline bool operator==(bytestring const& s1, const char* s2) { return strcmp(c_str(s1), s2) == 0; }
|
||||||
|
|
||||||
|
|
|
@ -3,25 +3,26 @@
|
||||||
#ifndef binpac_exception_h
|
#ifndef binpac_exception_h
|
||||||
#define binpac_exception_h
|
#define binpac_exception_h
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <cinttypes>
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace binpac {
|
namespace binpac {
|
||||||
|
|
||||||
class Exception {
|
class Exception {
|
||||||
public:
|
public:
|
||||||
Exception(const char* m = 0) : msg_("binpac exception: ") {
|
Exception(const char* m = nullptr) : msg_("binpac exception: ") {
|
||||||
if ( m )
|
if ( m )
|
||||||
append(m);
|
append(m);
|
||||||
// abort();
|
// abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void append(string m) { msg_ += m; }
|
void append(std::string m) { msg_ += m; }
|
||||||
string msg() const { return msg_; }
|
std::string msg() const { return msg_; }
|
||||||
const char* c_msg() const { return msg_.c_str(); }
|
const char* c_msg() const { return msg_.c_str(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string msg_;
|
std::string msg_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExceptionEnforceViolation : public Exception {
|
class ExceptionEnforceViolation : public Exception {
|
||||||
|
@ -46,7 +47,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
const char* location_;
|
const char* location_;
|
||||||
int64_t index_;
|
int64_t index_;
|
||||||
string expected_;
|
std::string expected_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExceptionInvalidCaseIndex : public Exception {
|
class ExceptionInvalidCaseIndex : public Exception {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
|
// See the file "COPYING" in the main distribution directory for copyright.
|
||||||
|
|
||||||
#ifndef binpac_regex_h
|
#ifndef binpac_regex_h
|
||||||
#define binpac_regex_h
|
#define binpac_regex_h
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "zeek/RE.h"
|
#include "zeek/RE.h"
|
||||||
|
|
||||||
#include "binpac.h"
|
#include "binpac.h"
|
||||||
|
@ -16,7 +20,7 @@ namespace binpac {
|
||||||
// Note, this must be declared/defined here, and inline, because the RE
|
// Note, this must be declared/defined here, and inline, because the RE
|
||||||
// functionality can only be used when compiling from inside Zeek.
|
// functionality can only be used when compiling from inside Zeek.
|
||||||
// A copy is made of any FlowBuffer policy struct data passed.
|
// A copy is made of any FlowBuffer policy struct data passed.
|
||||||
inline void init(FlowBuffer::Policy* fbp = 0);
|
inline void init(FlowBuffer::Policy* fbp = nullptr);
|
||||||
|
|
||||||
// Internal vector recording not yet compiled matchers.
|
// Internal vector recording not yet compiled matchers.
|
||||||
extern std::vector<zeek::RE_Matcher*>* uncompiled_re_matchers;
|
extern std::vector<zeek::RE_Matcher*>* uncompiled_re_matchers;
|
||||||
|
@ -50,8 +54,8 @@ inline void RegExMatcher::init() {
|
||||||
if ( ! uncompiled_re_matchers )
|
if ( ! uncompiled_re_matchers )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for ( size_t i = 0; i < uncompiled_re_matchers->size(); ++i ) {
|
for ( const auto& matcher : *uncompiled_re_matchers ) {
|
||||||
if ( ! (*uncompiled_re_matchers)[i]->Compile() ) {
|
if ( ! matcher->Compile() ) {
|
||||||
fprintf(stderr, "binpac: cannot compile regular expression\n");
|
fprintf(stderr, "binpac: cannot compile regular expression\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "pac_common.h"
|
#include "pac_common.h"
|
||||||
#include "pac_decl.h"
|
#include "pac_decl.h"
|
||||||
#include "pac_exception.h"
|
#include "pac_exception.h"
|
||||||
|
@ -177,9 +176,6 @@ int compile(const char* filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage() {
|
void usage() {
|
||||||
#ifdef BINPAC_VERSION
|
|
||||||
fprintf(stderr, "binpac version %s\n", BINPAC_VERSION);
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "usage: binpac [options] <pac files>\n");
|
fprintf(stderr, "usage: binpac [options] <pac files>\n");
|
||||||
fprintf(stderr, " <pac files> | pac-language input files\n");
|
fprintf(stderr, " <pac files> | pac-language input files\n");
|
||||||
fprintf(stderr, " -d <dir> | use given directory for compiler output\n");
|
fprintf(stderr, " -d <dir> | use given directory for compiler output\n");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue