Skip to content

Commit

Permalink
some codacy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Nov 17, 2024
1 parent 80144d1 commit 5ae9b8b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/dpp/socketengines/epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct socket_engine_epoll : public socket_engine_base {
socket_engine_epoll& operator=(const socket_engine_epoll&) = delete;
socket_engine_epoll& operator=(socket_engine_epoll&&) = delete;

socket_engine_epoll(cluster* creator) : socket_engine_base(creator), epoll_handle(epoll_create(socket_engine_epoll::epoll_hint)) {
explicit socket_engine_epoll(cluster* creator) : socket_engine_base(creator), epoll_handle(epoll_create(socket_engine_epoll::epoll_hint)) {
events.resize(socket_engine_epoll::epoll_hint);
if (epoll_handle == -1) {
throw dpp::connection_exception("Failed to initialise epoll()");
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/socketengines/kqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct socket_engine_kqueue : public socket_engine_base {
socket_engine_kqueue& operator=(const socket_engine_kqueue&) = default;
socket_engine_kqueue& operator=(socket_engine_kqueue&&) = default;

socket_engine_kqueue(cluster* creator) : socket_engine_base(creator), kqueue_handle(kqueue()) {
explicit socket_engine_kqueue(cluster* creator) : socket_engine_base(creator), kqueue_handle(kqueue()) {
change_list.resize(8);
ke_list.resize(16);
if (kqueue_handle == -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/socketengines/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct socket_engine_poll : public socket_engine_base {
return r;
}

socket_engine_poll(cluster* creator) : socket_engine_base(creator) { };
explicit socket_engine_poll(cluster* creator) : socket_engine_base(creator) { };

protected:

Expand Down
9 changes: 5 additions & 4 deletions src/sockettest/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

#include <dpp/dpp.h>
#include <iostream>
#include <thread>
#include <unistd.h>
#include <dpp/dns.h>
#include <dpp/sslclient.h>
#include <string_view>

int main() {
dpp::cluster cl("no-token");
Expand All @@ -51,7 +50,7 @@ int main() {
int r = 0;
do {
char buf[128]{0};
r = ::read(e.fd, buf, 127);
r = ::read(e.fd, buf, sizeof(buf));

Check notice on line 53 in src/sockettest/socket.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/sockettest/socket.cpp#L53

Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20).
if (r > 0) {
buf[127] = 0;
std::cout << buf;
Expand All @@ -65,7 +64,9 @@ int main() {
},
[](dpp::socket fd, const struct dpp::socket_events& e) {
std::cout << "WANT_WRITE event on socket " << fd << "\n";
::write(e.fd, "GET / HTTP/1.0\r\nConnection: close\r\n\r\n", strlen("GET / HTTP/1.0\r\nConnection: close\r\n\r\n"));
constexpr std::string_view request{"GET / HTTP/1.0\r\nConnection: close\r\n\r\n"};
auto written = ::write(e.fd, request.data(), request.length());
std::cout << "Written: " << written << "\n";
},
[](dpp::socket fd, const struct dpp::socket_events&, int error_code) {
std::cout << "WANT_ERROR event on socket " << fd << " with code " << error_code << "\n";
Expand Down

0 comments on commit 5ae9b8b

Please sign in to comment.