Skip to content

Commit

Permalink
Fixing various issues reported by static code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaa committed Aug 17, 2024
1 parent 155abd8 commit 920c8e2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 22 deletions.
5 changes: 2 additions & 3 deletions src/ChunkedReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ class ChunkedReaderImpl : public DataReader {
if (eat_chunk_padding_) {
eat_chunk_padding_ = false;

char ch = {};
if ((ch = stream_->Getc()) != '\r') {
if (stream_->Getc() != '\r') {
throw ParseException("Chunk: Missing padding CR!");
}

if ((ch = stream_->Getc()) != '\n') {
if (stream_->Getc() != '\n') {
throw ParseException("Chunk: Missing padding LF!");
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/ChunkedWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ class ChunkedWriterImpl : public DataWriter {
void Write(const write_buffers_t& buffers) override {
const auto len = boost::asio::buffer_size(buffers);
buffers_.resize(1);
for(auto &b : buffers) {
buffers_.push_back(b);
}

std::copy(buffers.begin(), buffers.end(), std::back_insert_iterator{buffers_});
DoWrite(len);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionPoolImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ConnectionPoolImpl
};


ConnectionPoolImpl(RestClient& owner)
explicit ConnectionPoolImpl(RestClient& owner)
: owner_{owner}, properties_{owner.GetConnectionProperties()}
, cache_cleanup_timer_{owner.GetIoService()}
{
Expand Down
2 changes: 1 addition & 1 deletion src/ReplyImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ReplyImpl::~ReplyImpl() {
<< "received data.");
connection_->GetSocket().Close();
connection_.reset();
} catch(std::exception& ex) {
} catch(const std::exception& ex) {
RESTC_CPP_LOG_WARN_("~ReplyImpl(): Caught exception:" << ex.what());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/RequestBodyStringImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace impl {
class RequestBodyStringImpl : public RequestBody
{
public:
RequestBodyStringImpl(string body)
: body_{move(body)}
explicit RequestBodyStringImpl(string body)
: body_{std::move(body)}
{
}

Expand Down
19 changes: 9 additions & 10 deletions src/RequestImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ constexpr char SOCKS5_HOSTNAME_ADDR = 0x03;
* ipv4: 1.2.3.4:123 -> "1.2.3.4", 123
* ipv6: [fe80::4479:f6ff:fea3:aa23]:123 -> "fe80::4479:f6ff:fea3:aa23", 123
*/
pair<string, uint16_t> ParseAddress(const std::string addr) {
pair<string, uint16_t> ParseAddress(const std::string& addr) {
auto pos = addr.find('['); // IPV6
string host;
string port;
if (pos != string::npos) {
auto host = addr.substr(1); // strip '['
host = addr.substr(1); // strip '['
pos = host.find(']');
if (pos == string::npos) {
throw ParseException{"IPv6 address must have a ']'"};
}
port = host.substr(pos);
host = host.substr(0, pos);
host.resize(pos);

if (port.size() < 3 || (host.at(1) != ':')) {
throw ParseException{"Need `]:<port>` in "s + addr};
Expand Down Expand Up @@ -179,7 +179,7 @@ void ParseAddressIntoSocke5ConnectRequest(const std::string& addr,
}

// Return 0 whene there is no more bytes to read
size_t ValidateCompleteSocks5ConnectReply(uint8_t *buf, size_t len) {
size_t ValidateCompleteSocks5ConnectReply(const uint8_t *buf, size_t len) {
if (len < 5) {
throw RestcCppException{"SOCKS5 server connect reply must start at minimum 5 bytes"s};
}
Expand Down Expand Up @@ -223,7 +223,7 @@ size_t ValidateCompleteSocks5ConnectReply(uint8_t *buf, size_t len) {

void DoSocks5Handshake(Connection& connection,
const Url& url,
const Request::Properties properties,
const Request::Properties& properties,
Context& ctx) {

assert(properties.proxy.type == Request::Proxy::Type::SOCKS5);
Expand Down Expand Up @@ -482,8 +482,9 @@ class RequestImpl : public Request {
}

// Add arguments to the path as ?name=value&name=value...
bool first_arg = true;

if (add_url_args_) {
bool first_arg = true;
// Normal processing.
request_buffer << url_encode(parsed_url_.GetPath());
for(const auto& arg : properties_->args) {
Expand Down Expand Up @@ -609,9 +610,7 @@ class RequestImpl : public Request {

auto ep = resolver.async_resolve(q, ctx.GetYield());
const decltype(ep) addr_end;
for(; ep != addr_end; ++ep)
if (ep != addr_end) {

for(; ep != addr_end; ++ep) {
RESTC_CPP_LOG_TRACE_("ep=" << ep->endpoint() << ", protocol=" << ep->endpoint().protocol().protocol());

if (protocol == ep->endpoint().protocol()) {
Expand Down Expand Up @@ -955,7 +954,7 @@ class RequestImpl : public Request {
* received.
*/

return move(reply);
return reply;
}


Expand Down
3 changes: 1 addition & 2 deletions src/RestClientImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ using namespace std;

namespace restc_cpp {


class RestClientImpl : public RestClient {
class RestClientImpl final : public RestClient {
public:

/*! Proper shutdown handling
Expand Down

0 comments on commit 920c8e2

Please sign in to comment.