src: Use C++11 value-initialization, instead of memset-ing 0
This commit is contained in:
parent
05d5c404e2
commit
5dc060c1a2
|
@ -1666,7 +1666,6 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) {
|
|||
namespace {
|
||||
int start_listen(HttpServer *sv, struct ev_loop *loop, Sessions *sessions,
|
||||
const Config *config) {
|
||||
addrinfo hints;
|
||||
int r;
|
||||
bool ok = false;
|
||||
const char *addr = nullptr;
|
||||
|
@ -1674,7 +1673,7 @@ int start_listen(HttpServer *sv, struct ev_loop *loop, Sessions *sessions,
|
|||
auto acceptor = std::make_shared<AcceptHandler>(sv, sessions, config);
|
||||
auto service = util::utos(config->port);
|
||||
|
||||
memset(&hints, 0, sizeof(addrinfo));
|
||||
addrinfo hints{};
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
|
|
@ -841,9 +841,8 @@ process_time_stats(const std::vector<std::unique_ptr<Worker>> &workers) {
|
|||
namespace {
|
||||
void resolve_host() {
|
||||
int rv;
|
||||
addrinfo hints, *res;
|
||||
addrinfo hints{}, *res;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
|
@ -906,8 +905,7 @@ std::vector<std::string> parse_uris(Iterator first, Iterator last) {
|
|||
|
||||
// First URI is treated specially. We use scheme, host and port of
|
||||
// this URI and ignore those in the remaining URIs if present.
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
|
||||
if (first == last) {
|
||||
std::cerr << "no URI available" << std::endl;
|
||||
|
@ -935,8 +933,7 @@ std::vector<std::string> parse_uris(Iterator first, Iterator last) {
|
|||
reqlines.push_back(get_reqline(uri, u));
|
||||
|
||||
for (; first != last; ++first) {
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
|
||||
auto uri = (*first).c_str();
|
||||
|
||||
|
@ -1333,8 +1330,7 @@ int main(int argc, char **argv) {
|
|||
config.data_length = data_stat.st_size;
|
||||
}
|
||||
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(struct sigaction));
|
||||
struct sigaction act {};
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigaction(SIGPIPE, &act, nullptr);
|
||||
|
||||
|
|
|
@ -191,8 +191,7 @@ void check_rewrite_location_uri(const std::string &want, const std::string &uri,
|
|||
const std::string &match_host,
|
||||
const std::string &req_authority,
|
||||
const std::string &upstream_scheme) {
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
CU_ASSERT(0 == http_parser_parse_url(uri.c_str(), uri.size(), 0, &u));
|
||||
auto got = http2::rewrite_location_uri(uri, u, match_host, req_authority,
|
||||
upstream_scheme);
|
||||
|
|
|
@ -501,9 +501,8 @@ bool HttpClient::need_upgrade() const {
|
|||
|
||||
int HttpClient::resolve_host(const std::string &host, uint16_t port) {
|
||||
int rv;
|
||||
addrinfo hints;
|
||||
this->host = host;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
addrinfo hints{};
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
|
@ -1260,8 +1259,7 @@ bool HttpClient::add_request(const std::string &uri,
|
|||
const nghttp2_data_provider *data_prd,
|
||||
int64_t data_length,
|
||||
const nghttp2_priority_spec &pri_spec, int level) {
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1485,8 +1483,7 @@ void update_html_parser(HttpClient *client, Request *req, const uint8_t *data,
|
|||
auto uri = strip_fragment(p.first.c_str());
|
||||
auto res_type = p.second;
|
||||
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) == 0 &&
|
||||
util::fieldeq(uri.c_str(), u, req->uri.c_str(), req->u, UF_SCHEMA) &&
|
||||
util::fieldeq(uri.c_str(), u, req->uri.c_str(), req->u, UF_HOST) &&
|
||||
|
@ -1650,8 +1647,7 @@ int on_begin_headers_callback(nghttp2_session *session,
|
|||
}
|
||||
case NGHTTP2_PUSH_PROMISE: {
|
||||
auto stream_id = frame->push_promise.promised_stream_id;
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
// TODO Set pri and level
|
||||
nghttp2_priority_spec pri_spec;
|
||||
|
||||
|
@ -1820,8 +1816,7 @@ int on_frame_recv_callback2(nghttp2_session *session,
|
|||
uri += "://";
|
||||
uri += authority->value;
|
||||
uri += path->value;
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) != 0) {
|
||||
nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE,
|
||||
frame->push_promise.promised_stream_id,
|
||||
|
@ -2299,8 +2294,7 @@ int run(char **uris, int n) {
|
|||
std::vector<std::tuple<std::string, nghttp2_data_provider *, int64_t>>
|
||||
requests;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
auto uri = strip_fragment(uris[i]);
|
||||
if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) != 0) {
|
||||
std::cerr << "[ERROR] Could not parse URI " << uri << std::endl;
|
||||
|
@ -2701,8 +2695,7 @@ int main(int argc, char **argv) {
|
|||
nghttp2_option_set_peer_max_concurrent_streams(
|
||||
config.http2_option, config.peer_max_concurrent_streams);
|
||||
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(struct sigaction));
|
||||
struct sigaction act {};
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigaction(SIGPIPE, &act, nullptr);
|
||||
reset_timer();
|
||||
|
|
|
@ -371,8 +371,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
set_color_output(color || isatty(fileno(stdout)));
|
||||
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(struct sigaction));
|
||||
struct sigaction act {};
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigaction(SIGPIPE, &act, nullptr);
|
||||
|
||||
|
|
11
src/shrpx.cc
11
src/shrpx.cc
|
@ -119,12 +119,11 @@ const int GRACEFUL_SHUTDOWN_SIGNAL = SIGQUIT;
|
|||
namespace {
|
||||
int resolve_hostname(sockaddr_union *addr, size_t *addrlen,
|
||||
const char *hostname, uint16_t port, int family) {
|
||||
addrinfo hints;
|
||||
int rv;
|
||||
|
||||
auto service = util::utos(port);
|
||||
memset(&hints, 0, sizeof(addrinfo));
|
||||
|
||||
addrinfo hints{};
|
||||
hints.ai_family = family;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
#ifdef AI_ADDRCONFIG
|
||||
|
@ -279,12 +278,11 @@ std::unique_ptr<AcceptHandler> create_acceptor(ConnectionHandler *handler,
|
|||
}
|
||||
}
|
||||
|
||||
addrinfo hints;
|
||||
int fd = -1;
|
||||
int rv;
|
||||
|
||||
auto service = util::utos(get_config()->port);
|
||||
memset(&hints, 0, sizeof(addrinfo));
|
||||
addrinfo hints{};
|
||||
hints.ai_family = family;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
@ -849,7 +847,7 @@ int16_t DEFAULT_DOWNSTREAM_PORT = 80;
|
|||
|
||||
namespace {
|
||||
void fill_default_config() {
|
||||
memset(mod_config(), 0, sizeof(*mod_config()));
|
||||
*mod_config() = {};
|
||||
|
||||
mod_config()->verbose = false;
|
||||
mod_config()->daemon = false;
|
||||
|
@ -2359,8 +2357,7 @@ int main(int argc, char **argv) {
|
|||
reset_timer();
|
||||
}
|
||||
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(struct sigaction));
|
||||
struct sigaction act {};
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigaction(SIGPIPE, &act, nullptr);
|
||||
|
||||
|
|
|
@ -1575,8 +1575,7 @@ int parse_config(const char *opt, const char *optarg,
|
|||
return 0;
|
||||
case SHRPX_OPTID_BACKEND_HTTP_PROXY_URI: {
|
||||
// parse URI and get hostname, port and optionally userinfo.
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
int rv = http_parser_parse_url(optarg, strlen(optarg), 0, &u);
|
||||
if (rv == 0) {
|
||||
std::string val;
|
||||
|
|
|
@ -129,9 +129,8 @@ ConnectionHandler::~ConnectionHandler() {
|
|||
}
|
||||
|
||||
void ConnectionHandler::worker_reopen_log_files() {
|
||||
WorkerEvent wev;
|
||||
WorkerEvent wev{};
|
||||
|
||||
memset(&wev, 0, sizeof(wev));
|
||||
wev.type = REOPEN_LOG;
|
||||
|
||||
for (auto &worker : workers_) {
|
||||
|
@ -141,9 +140,8 @@ void ConnectionHandler::worker_reopen_log_files() {
|
|||
|
||||
void ConnectionHandler::worker_renew_ticket_keys(
|
||||
const std::shared_ptr<TicketKeys> &ticket_keys) {
|
||||
WorkerEvent wev;
|
||||
WorkerEvent wev{};
|
||||
|
||||
memset(&wev, 0, sizeof(wev));
|
||||
wev.type = RENEW_TICKET_KEYS;
|
||||
wev.ticket_keys = ticket_keys;
|
||||
|
||||
|
@ -216,8 +214,7 @@ void ConnectionHandler::graceful_shutdown_worker() {
|
|||
return;
|
||||
}
|
||||
|
||||
WorkerEvent wev;
|
||||
memset(&wev, 0, sizeof(wev));
|
||||
WorkerEvent wev{};
|
||||
wev.type = GRACEFUL_SHUTDOWN;
|
||||
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
|
@ -266,8 +263,7 @@ int ConnectionHandler::handle_connection(int fd, sockaddr *addr, int addrlen) {
|
|||
LOG(INFO) << "Dispatch connection to worker #" << idx;
|
||||
}
|
||||
++worker_round_robin_cnt_;
|
||||
WorkerEvent wev;
|
||||
memset(&wev, 0, sizeof(wev));
|
||||
WorkerEvent wev{};
|
||||
wev.type = NEW_CONNECTION;
|
||||
wev.client_fd = fd;
|
||||
memcpy(&wev.client_addr, addr, addrlen);
|
||||
|
|
|
@ -621,8 +621,7 @@ void Downstream::rewrite_location_response_header(
|
|||
if (!hd) {
|
||||
return;
|
||||
}
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
int rv =
|
||||
http_parser_parse_url((*hd).value.c_str(), (*hd).value.size(), 0, &u);
|
||||
if (rv != 0) {
|
||||
|
|
|
@ -1482,8 +1482,7 @@ int Http2Upstream::on_downstream_reset(bool no_retry) {
|
|||
|
||||
int Http2Upstream::prepare_push_promise(Downstream *downstream) {
|
||||
int rv;
|
||||
http_parser_url u;
|
||||
memset(&u, 0, sizeof(u));
|
||||
http_parser_url u{};
|
||||
rv = http_parser_parse_url(downstream->get_request_path().c_str(),
|
||||
downstream->get_request_path().size(), 0, &u);
|
||||
if (rv != 0) {
|
||||
|
@ -1513,8 +1512,7 @@ int Http2Upstream::prepare_push_promise(Downstream *downstream) {
|
|||
const char *relq = nullptr;
|
||||
size_t relqlen = 0;
|
||||
|
||||
http_parser_url v;
|
||||
memset(&v, 0, sizeof(v));
|
||||
http_parser_url v{};
|
||||
rv = http_parser_parse_url(link_url, link_urllen, 0, &v);
|
||||
if (rv != 0) {
|
||||
assert(link_urllen);
|
||||
|
|
|
@ -452,8 +452,7 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler)
|
|||
: 0,
|
||||
!get_config()->http2_proxy),
|
||||
handler_(handler), session_(nullptr) {
|
||||
spdylay_session_callbacks callbacks;
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
spdylay_session_callbacks callbacks{};
|
||||
callbacks.send_callback = send_callback;
|
||||
callbacks.recv_callback = recv_callback;
|
||||
callbacks.on_stream_close_callback = on_stream_close_callback;
|
||||
|
|
|
@ -348,8 +348,7 @@ std::string iso8601_date(int64_t ms) {
|
|||
}
|
||||
|
||||
time_t parse_http_date(const std::string &s) {
|
||||
tm tm;
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
tm tm{};
|
||||
char *r = strptime(s.c_str(), "%a, %d %b %Y %H:%M:%S GMT", &tm);
|
||||
if (r == 0) {
|
||||
return 0;
|
||||
|
@ -637,9 +636,8 @@ void write_uri_field(std::ostream &o, const char *uri, const http_parser_url &u,
|
|||
}
|
||||
|
||||
bool numeric_host(const char *hostname) {
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *res;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
struct addrinfo hints {};
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
if (getaddrinfo(hostname, nullptr, &hints, &res)) {
|
||||
|
|
Loading…
Reference in New Issue