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