diff --git a/tools/binpac/lib/binpac_buffer.h b/tools/binpac/lib/binpac_buffer.h index f7cf012950..bd34c9769d 100644 --- a/tools/binpac/lib/binpac_buffer.h +++ b/tools/binpac/lib/binpac_buffer.h @@ -17,7 +17,7 @@ public: int contract_threshold; }; - enum LineBreakStyle { + enum LineBreakStyle : uint8_t { CR_OR_LF, // CR or LF or CRLF STRICT_CRLF, // CR followed by LF CR_LF_NUL, // CR or LF or CR-LF or CR-NUL @@ -142,13 +142,13 @@ protected: LineBreakStyle linebreak_style_default; unsigned char linebreaker_; - enum { + enum : uint8_t { UNKNOWN_MODE, LINE_MODE, FRAME_MODE, } mode_; - enum { + enum : uint8_t { CR_OR_LF_0, CR_OR_LF_1, STRICT_CRLF_0, @@ -163,7 +163,7 @@ protected: static Policy policy; }; -typedef FlowBuffer* flow_buffer_t; +using flow_buffer_t = FlowBuffer*; } // namespace binpac diff --git a/tools/binpac/lib/binpac_bytestring.h b/tools/binpac/lib/binpac_bytestring.h index 6a33f2eb8f..152ef7c42c 100644 --- a/tools/binpac/lib/binpac_bytestring.h +++ b/tools/binpac/lib/binpac_bytestring.h @@ -3,7 +3,7 @@ #ifndef binpac_bytestring_h #define binpac_bytestring_h -#include +#include #include #include "binpac.h" @@ -16,7 +16,7 @@ class datastring; template class const_datastring { 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) {} @@ -49,7 +49,7 @@ private: T const* end_; }; -typedef const_datastring const_bytestring; +using const_bytestring = const_datastring; template class datastring { @@ -65,6 +65,9 @@ public: explicit datastring(const_datastring const& x) { set_const(x.begin(), x.length()); } datastring const& operator=(datastring const& x) { + if ( this == &x ) + return *this; + BINPAC_ASSERT(! data_); set(x.data(), x.length()); return *this; @@ -76,7 +79,7 @@ public: } void clear() { - data_ = 0; + data_ = nullptr; length_ = 0; } @@ -119,13 +122,11 @@ private: int length_; }; -typedef datastring bytestring; +using bytestring = datastring; inline const char* c_str(bytestring const& s) { return (const char*)s.begin(); } -inline std::string std_str(const_bytestring const& s) { - return std::string((const char*)s.begin(), (const char*)s.end()); -} +inline std::string std_str(const_bytestring const& s) { return {(const char*)s.begin(), (const char*)s.end()}; } inline bool operator==(bytestring const& s1, const char* s2) { return strcmp(c_str(s1), s2) == 0; } diff --git a/tools/binpac/lib/binpac_exception.h b/tools/binpac/lib/binpac_exception.h index 8578ae83fc..52bd6f7421 100644 --- a/tools/binpac/lib/binpac_exception.h +++ b/tools/binpac/lib/binpac_exception.h @@ -3,25 +3,26 @@ #ifndef binpac_exception_h #define binpac_exception_h -#include -#include +#include +#include +#include namespace binpac { class Exception { public: - Exception(const char* m = 0) : msg_("binpac exception: ") { + Exception(const char* m = nullptr) : msg_("binpac exception: ") { if ( m ) append(m); // abort(); } - void append(string m) { msg_ += m; } - string msg() const { return msg_; } + void append(std::string m) { msg_ += m; } + std::string msg() const { return msg_; } const char* c_msg() const { return msg_.c_str(); } protected: - string msg_; + std::string msg_; }; class ExceptionEnforceViolation : public Exception { @@ -46,7 +47,7 @@ public: protected: const char* location_; int64_t index_; - string expected_; + std::string expected_; }; class ExceptionInvalidCaseIndex : public Exception { diff --git a/tools/binpac/lib/binpac_regex.h b/tools/binpac/lib/binpac_regex.h index d8e2a05c23..6e1ea11101 100644 --- a/tools/binpac/lib/binpac_regex.h +++ b/tools/binpac/lib/binpac_regex.h @@ -1,6 +1,10 @@ +// See the file "COPYING" in the main distribution directory for copyright. + #ifndef binpac_regex_h #define binpac_regex_h +#include + #include "zeek/RE.h" #include "binpac.h" @@ -16,7 +20,7 @@ namespace binpac { // Note, this must be declared/defined here, and inline, because the RE // functionality can only be used when compiling from inside Zeek. // 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. extern std::vector* uncompiled_re_matchers; @@ -50,8 +54,8 @@ inline void RegExMatcher::init() { if ( ! uncompiled_re_matchers ) return; - for ( size_t i = 0; i < uncompiled_re_matchers->size(); ++i ) { - if ( ! (*uncompiled_re_matchers)[i]->Compile() ) { + for ( const auto& matcher : *uncompiled_re_matchers ) { + if ( ! matcher->Compile() ) { fprintf(stderr, "binpac: cannot compile regular expression\n"); exit(1); } diff --git a/tools/binpac/src/pac_main.cc b/tools/binpac/src/pac_main.cc index 83cf8ba15c..f3e5847f52 100644 --- a/tools/binpac/src/pac_main.cc +++ b/tools/binpac/src/pac_main.cc @@ -3,7 +3,6 @@ #include #include -#include "config.h" #include "pac_common.h" #include "pac_decl.h" #include "pac_exception.h" @@ -177,9 +176,6 @@ int compile(const char* filename) { } void usage() { -#ifdef BINPAC_VERSION - fprintf(stderr, "binpac version %s\n", BINPAC_VERSION); -#endif fprintf(stderr, "usage: binpac [options] \n"); fprintf(stderr, " | pac-language input files\n"); fprintf(stderr, " -d | use given directory for compiler output\n");