Unverified Commit 2aaa2311 authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #659 from dennisjenkins75/master

Lots of misc cppcheck fixes
parents f453c99b 14bafd53
...@@ -140,7 +140,7 @@ struct Info { ...@@ -140,7 +140,7 @@ struct Info {
}; };
struct InfoBuilder { struct InfoBuilder {
InfoBuilder(Info* info); explicit InfoBuilder(Info* info);
InfoBuilder& termsOfService(std::string value); InfoBuilder& termsOfService(std::string value);
InfoBuilder& contact(std::string name, std::string url, std::string email); InfoBuilder& contact(std::string name, std::string url, std::string email);
...@@ -162,10 +162,16 @@ struct DataType { ...@@ -162,10 +162,16 @@ struct DataType {
template<typename T> template<typename T>
struct DataTypeT : public DataType { struct DataTypeT : public DataType {
const char* typeName() const { return Traits::DataTypeInfo<T>::typeName(); } const char* typeName() const override {
const char* format() const { return Traits::DataTypeInfo<T>::format(); } return Traits::DataTypeInfo<T>::typeName();
}
const char* format() const override {
return Traits::DataTypeInfo<T>::format();
}
bool validate(const std::string& input) const { return Traits::DataTypeValidation<T>::validate(input); } bool validate(const std::string& input) const override {
return Traits::DataTypeValidation<T>::validate(input);
}
virtual ~DataTypeT() {} virtual ~DataTypeT() {}
}; };
...@@ -290,7 +296,7 @@ private: ...@@ -290,7 +296,7 @@ private:
}; };
struct PathBuilder { struct PathBuilder {
PathBuilder(Path* path); explicit PathBuilder(Path* path);
template<typename... Mimes> template<typename... Mimes>
PathBuilder& produces(Mimes... mimes) { PathBuilder& produces(Mimes... mimes) {
...@@ -364,10 +370,10 @@ private: ...@@ -364,10 +370,10 @@ private:
struct SubPath { struct SubPath {
SubPath(std::string prefix, PathGroup* paths); SubPath(std::string prefix, PathGroup* paths);
PathBuilder route(std::string name, Http::Method method, std::string description = ""); PathBuilder route(const std::string &name, Http::Method method, std::string description = "");
PathBuilder route(PathDecl fragment, std::string description = ""); PathBuilder route(PathDecl fragment, std::string description = "");
SubPath path(std::string prefix); SubPath path(const std::string &prefix);
template<typename T> template<typename T>
void parameter(std::string name, std::string description) { void parameter(std::string name, std::string description) {
...@@ -447,7 +453,7 @@ private: ...@@ -447,7 +453,7 @@ private:
class Swagger { class Swagger {
public: public:
Swagger(const Description& description) explicit Swagger(const Description& description)
: description_(description) : description_(description)
, uiPath_() , uiPath_()
, uiDirectory_() , uiDirectory_()
......
...@@ -21,6 +21,10 @@ public: ...@@ -21,6 +21,10 @@ public:
Options& threads(int val); Options& threads(int val);
Options& threadsName(const std::string& val); Options& threadsName(const std::string& val);
Options& flags(Flags<Tcp::Options> flags); Options& flags(Flags<Tcp::Options> flags);
Options& flags(Tcp::Options tcp_opts) {
flags(Flags<Tcp::Options>(tcp_opts));
return *this;
}
Options& backlog(int val); Options& backlog(int val);
Options& maxRequestSize(size_t val); Options& maxRequestSize(size_t val);
Options& maxResponseSize(size_t val); Options& maxResponseSize(size_t val);
......
...@@ -58,8 +58,7 @@ public: ...@@ -58,8 +58,7 @@ public:
Flags() : val(T::None) { Flags() : val(T::None) {
} }
Flags(T _val) : val(_val) explicit Flags(T _val) : val(_val) {
{
} }
#define DEFINE_BITWISE_OP_CONST(Op) \ #define DEFINE_BITWISE_OP_CONST(Op) \
......
...@@ -213,7 +213,7 @@ public: ...@@ -213,7 +213,7 @@ public:
friend class ResponseWriter; friend class ResponseWriter;
Timeout(Timeout&& other) explicit Timeout(Timeout&& other)
: handler(other.handler) : handler(other.handler)
, request(std::move(other.request)) , request(std::move(other.request))
, transport(other.transport) , transport(other.transport)
...@@ -221,6 +221,7 @@ public: ...@@ -221,6 +221,7 @@ public:
, timerFd(other.timerFd) , timerFd(other.timerFd)
, peer(std::move(other.peer)) , peer(std::move(other.peer))
{ {
// cppcheck-suppress useInitializationList
other.timerFd = -1; other.timerFd = -1;
} }
...@@ -773,7 +774,7 @@ namespace Private { ...@@ -773,7 +774,7 @@ namespace Private {
feed(data, len); feed(data, len);
} }
void reset() { void reset() override {
ParserBase::reset(); ParserBase::reset();
request.headers_.clear(); request.headers_.clear();
...@@ -814,16 +815,16 @@ namespace Private { ...@@ -814,16 +815,16 @@ namespace Private {
class Handler : public Tcp::Handler { class Handler : public Tcp::Handler {
public: public:
void onInput(const char* buffer, size_t len, const std::shared_ptr<Tcp::Peer>& peer); void onInput(const char* buffer, size_t len, const std::shared_ptr<Tcp::Peer>& peer) override;
void onConnection(const std::shared_ptr<Tcp::Peer>& peer); void onConnection(const std::shared_ptr<Tcp::Peer>& peer) override;
void onDisconnection(const std::shared_ptr<Tcp::Peer>& peer); void onDisconnection(const std::shared_ptr<Tcp::Peer>& peer) override;
virtual void onRequest(const Request& request, ResponseWriter response) = 0; virtual void onRequest(const Request& request, ResponseWriter response) = 0;
virtual void onTimeout(const Request& request, ResponseWriter response); virtual void onTimeout(const Request& request, ResponseWriter response);
virtual ~Handler() { } virtual ~Handler() override { }
private: private:
Private::Parser<Http::Request>& getParser(const std::shared_ptr<Tcp::Peer>& peer) const; Private::Parser<Http::Request>& getParser(const std::shared_ptr<Tcp::Peer>& peer) const;
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
explicit Listener(const Address& address); explicit Listener(const Address& address);
void init( void init(
size_t workers, size_t workers,
Flags<Options> options = Options::None, Flags<Options> options = Flags<Options>(Options::None),
const std::string& workersName = "", const std::string& workersName = "",
int backlog = Const::MaxBacklog); int backlog = Const::MaxBacklog);
void setHandler(const std::shared_ptr<Handler>& handler); void setHandler(const std::shared_ptr<Handler>& handler);
......
...@@ -83,10 +83,10 @@ public: ...@@ -83,10 +83,10 @@ public:
} }
event_fd = TRY_RET(eventfd(0, EFD_NONBLOCK)); event_fd = TRY_RET(eventfd(0, EFD_NONBLOCK));
Tag tag(event_fd); Tag tag_(event_fd);
poller.addFd(event_fd, NotifyOn::Read, tag); poller.addFd(event_fd, Flags<Polling::NotifyOn>(NotifyOn::Read), tag_);
return tag; return tag_;
} }
T *post(T *newData) { T *post(T *newData) {
...@@ -270,10 +270,10 @@ public: ...@@ -270,10 +270,10 @@ public:
} }
event_fd = TRY_RET(eventfd(0, EFD_NONBLOCK)); event_fd = TRY_RET(eventfd(0, EFD_NONBLOCK));
Tag tag(event_fd); Tag tag_(event_fd);
poller.addFd(event_fd, NotifyOn::Read, tag); poller.addFd(event_fd, Flags<Polling::NotifyOn>(NotifyOn::Read), tag_);
return tag; return tag_;
} }
template < class U > template < class U >
......
...@@ -28,7 +28,9 @@ namespace Aio { ...@@ -28,7 +28,9 @@ namespace Aio {
// A set of fds that are ready // A set of fds that are ready
class FdSet { class FdSet {
public: public:
FdSet(std::vector<Polling::Event>&& events) FdSet() = delete;
explicit FdSet(std::vector<Polling::Event>&& events)
: events_() : events_()
{ {
events_.reserve(events.size()); events_.reserve(events.size());
...@@ -177,11 +179,8 @@ public: ...@@ -177,11 +179,8 @@ public:
class AsyncContext : public ExecutionContext { class AsyncContext : public ExecutionContext {
public: public:
explicit AsyncContext(size_t threads, const std::string& threadsName = "") explicit AsyncContext(size_t threads, const std::string& threadsName = "")
: threads_(threads) : threads_(threads), threadsName_(threadsName)
{ }
{
threadsName_ = threadsName;
}
virtual ~AsyncContext() {} virtual ~AsyncContext() {}
......
...@@ -117,7 +117,7 @@ Cookie::fromRaw(const char* str, size_t len) ...@@ -117,7 +117,7 @@ Cookie::fromRaw(const char* str, size_t len)
if (!match_until('=', cursor)) if (!match_until('=', cursor))
throw std::runtime_error("Invalid cookie, missing value"); throw std::runtime_error("Invalid cookie, missing value");
auto name = nameToken.text(); auto name_ = nameToken.text();
if (!cursor.advance(1)) if (!cursor.advance(1))
throw std::runtime_error("Invalid cookie, missing value"); throw std::runtime_error("Invalid cookie, missing value");
...@@ -125,9 +125,9 @@ Cookie::fromRaw(const char* str, size_t len) ...@@ -125,9 +125,9 @@ Cookie::fromRaw(const char* str, size_t len)
StreamCursor::Token valueToken(cursor); StreamCursor::Token valueToken(cursor);
match_until(';', cursor); match_until(';', cursor);
auto value = valueToken.text(); auto value_ = valueToken.text();
Cookie cookie(std::move(name), std::move(value)); Cookie cookie(std::move(name_), std::move(value_));
if (cursor.eof()) { if (cursor.eof()) {
return cookie; return cookie;
} }
...@@ -147,17 +147,16 @@ Cookie::fromRaw(const char* str, size_t len) ...@@ -147,17 +147,16 @@ Cookie::fromRaw(const char* str, size_t len)
else if (match_attribute(STR("Expires"), cursor, &cookie, &Cookie::expires)) ; else if (match_attribute(STR("Expires"), cursor, &cookie, &Cookie::expires)) ;
// ext // ext
else { else {
StreamCursor::Token nameToken(cursor); StreamCursor::Token nameToken_(cursor);
match_until('=', cursor); match_until('=', cursor);
auto name = nameToken.text(); auto name = nameToken_.text();
std::string value; std::string value;
if (!cursor.eof()) { if (!cursor.eof()) {
auto token = matchValue(cursor); auto token = matchValue(cursor);
value = token.text(); value = token.text();
} }
cookie.ext.insert(std::make_pair(std::move(name), std::move(value))); cookie.ext.insert(std::make_pair(std::move(name), std::move(value)));
} }
} while (!cursor.eof()); } while (!cursor.eof());
......
...@@ -203,7 +203,7 @@ SubPath::SubPath( ...@@ -203,7 +203,7 @@ SubPath::SubPath(
{ } { }
PathBuilder PathBuilder
SubPath::route(std::string name, Http::Method method, std::string description) { SubPath::route(const std::string &name, Http::Method method, std::string description) {
auto fullPath = prefix + name; auto fullPath = prefix + name;
Path path(std::move(fullPath), method, std::move(description)); Path path(std::move(fullPath), method, std::move(description));
std::copy(std::begin(parameters), std::end(parameters), std::back_inserter(path.parameters)); std::copy(std::begin(parameters), std::end(parameters), std::back_inserter(path.parameters));
...@@ -219,7 +219,7 @@ SubPath::route(PathDecl fragment, std::string description) { ...@@ -219,7 +219,7 @@ SubPath::route(PathDecl fragment, std::string description) {
} }
SubPath SubPath
SubPath::path(std::string prefix) { SubPath::path(const std::string &prefix) {
return SubPath(this->prefix + prefix, paths); return SubPath(this->prefix + prefix, paths);
} }
...@@ -397,7 +397,7 @@ Swagger::install(Rest::Router& router) { ...@@ -397,7 +397,7 @@ Swagger::install(Rest::Router& router) {
*/ */
struct Path { struct Path {
Path(const std::string& value) explicit Path(const std::string& value)
: value(value) : value(value)
, trailingSlashValue(value) , trailingSlashValue(value)
{ {
...@@ -406,32 +406,32 @@ Swagger::install(Rest::Router& router) { ...@@ -406,32 +406,32 @@ Swagger::install(Rest::Router& router) {
} }
static bool hasTrailingSlash(const Rest::Request& req) { static bool hasTrailingSlash(const Rest::Request& req) {
auto res = req.resource(); auto res_ = req.resource();
return res.back() == '/'; return res_.back() == '/';
} }
std::string stripPrefix(const Rest::Request& req) { std::string stripPrefix(const Rest::Request& req) {
auto res = req.resource(); auto res_ = req.resource();
if (!res.compare(0, value.size(), value)) { if (!res_.compare(0, value.size(), value)) {
return res.substr(value.size()); return res_.substr(value.size());
} }
return res; return res_;
} }
bool matches(const Rest::Request& req) const { bool matches(const Rest::Request& req) const {
auto res = req.resource(); auto res_ = req.resource();
if (value == res) if (value == res_)
return true; return true;
if (res == trailingSlashValue) if (res_ == trailingSlashValue)
return true; return true;
return false; return false;
} }
bool isPrefix(const Rest::Request& req) { bool isPrefix(const Rest::Request& req) {
auto res = req.resource(); auto res_ = req.resource();
return !res.compare(0, value.size(), value); return !res_.compare(0, value.size(), value);
} }
const std::string& withTrailingSlash() const { const std::string& withTrailingSlash() const {
......
...@@ -143,9 +143,9 @@ namespace Polling { ...@@ -143,9 +143,9 @@ namespace Polling {
, tag(_tag) , tag(_tag)
{ } { }
Epoll::Epoll() { Epoll::Epoll():
epoll_fd = TRY_RET(epoll_create(Const::MaxEvents)); epoll_fd([&](){return TRY_RET(epoll_create(Const::MaxEvents));}())
} { }
Epoll::~Epoll() Epoll::~Epoll()
{ {
...@@ -261,7 +261,7 @@ NotifyFd::bind(Polling::Epoll& poller) { ...@@ -261,7 +261,7 @@ NotifyFd::bind(Polling::Epoll& poller) {
event_fd = TRY_RET(eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC)); event_fd = TRY_RET(eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC));
Polling::Tag tag(event_fd); Polling::Tag tag(event_fd);
poller.addFd(event_fd, Polling::NotifyOn::Read, tag, Polling::Mode::Edge); poller.addFd(event_fd, Flags<Polling::NotifyOn>(Polling::NotifyOn::Read), tag, Polling::Mode::Edge);
return tag; return tag;
} }
......
...@@ -109,7 +109,7 @@ public: ...@@ -109,7 +109,7 @@ public:
Polling::Mode mode = Polling::Mode::Level) override { Polling::Mode mode = Polling::Mode::Level) override {
auto pollTag = encodeTag(key, tag); auto pollTag = encodeTag(key, tag);
poller.addFd(fd, interest, pollTag, mode); poller.addFd(fd, Flags<Polling::NotifyOn>(interest), pollTag, mode);
} }
void registerFdOneShot( void registerFdOneShot(
...@@ -120,7 +120,7 @@ public: ...@@ -120,7 +120,7 @@ public:
Polling::Mode mode = Polling::Mode::Level) override { Polling::Mode mode = Polling::Mode::Level) override {
auto pollTag = encodeTag(key, tag); auto pollTag = encodeTag(key, tag);
poller.addFdOneShot(fd, interest, pollTag, mode); poller.addFdOneShot(fd, Flags<Polling::NotifyOn>(interest), pollTag, mode);
} }
void modifyFd( void modifyFd(
...@@ -131,7 +131,7 @@ public: ...@@ -131,7 +131,7 @@ public:
Polling::Mode mode = Polling::Mode::Level) override { Polling::Mode mode = Polling::Mode::Level) override {
auto pollTag = encodeTag(key, tag); auto pollTag = encodeTag(key, tag);
poller.rearmFd(fd, interest, pollTag, mode); poller.rearmFd(fd, Flags<Polling::NotifyOn>(interest), pollTag, mode);
} }
void runOnce() override { void runOnce() override {
......
...@@ -205,7 +205,7 @@ Listener::bind(const Address& address) { ...@@ -205,7 +205,7 @@ Listener::bind(const Address& address) {
} }
make_non_blocking(fd); make_non_blocking(fd);
poller.addFd(fd, Polling::NotifyOn::Read, Polling::Tag(fd)); poller.addFd(fd, Flags<Polling::NotifyOn>(Polling::NotifyOn::Read), Polling::Tag(fd));
listen_fd = fd; listen_fd = fd;
auto transport = std::make_shared<Transport>(handler_); auto transport = std::make_shared<Transport>(handler_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment