Skip to content

Commit

Permalink
Merge pull request #1139 from pistacheio/no-memset
Browse files Browse the repository at this point in the history
fix: drop memset() calls
  • Loading branch information
kiplingw committed Jun 27, 2023
2 parents 63d5138 + 6d9a0af commit 17644dd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 28 deletions.
9 changes: 3 additions & 6 deletions src/client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,9 @@ namespace Pistache::Http::Experimental

void Connection::connect(const Address& addr)
{
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = addr.family();
hints.ai_socktype = SOCK_STREAM; /* Stream socket */
hints.ai_flags = 0;
hints.ai_protocol = 0;
struct addrinfo hints = {};
hints.ai_family = addr.family();
hints.ai_socktype = SOCK_STREAM; /* Stream socket */

const auto& host = addr.host();
const auto& port = addr.port().toString();
Expand Down
3 changes: 1 addition & 2 deletions src/common/mime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ namespace Pistache::Http::Mime
else if (val_ == 100)
return "q=1";

char buff[sizeof("q=0.99")];
memset(buff, 0, sizeof buff);
char buff[sizeof("q=0.99")] = {};
if (val_ % 10 == 0)
snprintf(buff, sizeof buff, "q=%.1f", val_ / 100.0);
else
Expand Down
9 changes: 3 additions & 6 deletions src/common/net.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ namespace Pistache
{
std::vector<std::string> result;

struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM; /* Stream socket */
hints.ai_flags = 0;
hints.ai_protocol = 0;
struct addrinfo hints = {};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM; /* Stream socket */

AddrInfo addressInfo;

Expand Down
10 changes: 4 additions & 6 deletions src/server/listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,10 @@ namespace Pistache::Tcp
{
addr_ = address;

struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = address.family();
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
hints.ai_protocol = 0;
struct addrinfo hints = {};
hints.ai_family = address.family();
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;

const auto& host = addr_.host();
const auto& port = addr_.port().toString();
Expand Down
3 changes: 1 addition & 2 deletions tests/listener_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ class DummyHandler : public Pistache::Http::Handler
SocketWrapper bind_free_port()
{
int sockfd; // listen on sock_fd, new connection on new_fd
addrinfo hints, *servinfo, *p;
struct addrinfo hints = {}, *servinfo, *p;

int yes = 1;
int rv;

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE; // use my IP
Expand Down
9 changes: 3 additions & 6 deletions tests/tcp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ namespace Pistache
public:
bool connect(const Pistache::Address& address)
{
struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_family = address.family();
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0;
hints.ai_protocol = 0;
struct addrinfo hints = {};
hints.ai_family = address.family();
hints.ai_socktype = SOCK_STREAM;

auto host = address.host();
auto port = address.port().toString();
Expand Down

0 comments on commit 17644dd

Please sign in to comment.