Changed to use auto (#1594)

This commit is contained in:
yhirose 2023-06-17 02:18:34 -04:00 committed by GitHub
parent 7ab5fb65b2
commit bd9612b81e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2013,7 +2013,7 @@ inline bool from_hex_to_i(const std::string &s, size_t i, size_t cnt,
val = 0; val = 0;
for (; cnt; i++, cnt--) { for (; cnt; i++, cnt--) {
if (!s[i]) { return false; } if (!s[i]) { return false; }
int v = 0; auto v = 0;
if (is_hex(s[i], v)) { if (is_hex(s[i], v)) {
val = val * 16 + v; val = val * 16 + v;
} else { } else {
@ -2074,8 +2074,8 @@ inline std::string base64_encode(const std::string &in) {
std::string out; std::string out;
out.reserve(in.size()); out.reserve(in.size());
int val = 0; auto val = 0;
int valb = -6; auto valb = -6;
for (auto c : in) { for (auto c : in) {
val = (val << 8) + static_cast<uint8_t>(c); val = (val << 8) + static_cast<uint8_t>(c);
@ -2206,7 +2206,7 @@ inline std::string decode_url(const std::string &s,
for (size_t i = 0; i < s.size(); i++) { for (size_t i = 0; i < s.size(); i++) {
if (s[i] == '%' && i + 1 < s.size()) { if (s[i] == '%' && i + 1 < s.size()) {
if (s[i + 1] == 'u') { if (s[i + 1] == 'u') {
int val = 0; auto val = 0;
if (from_hex_to_i(s, i + 2, 4, val)) { if (from_hex_to_i(s, i + 2, 4, val)) {
// 4 digits Unicode codes // 4 digits Unicode codes
char buff[4]; char buff[4];
@ -2217,7 +2217,7 @@ inline std::string decode_url(const std::string &s,
result += s[i]; result += s[i];
} }
} else { } else {
int val = 0; auto val = 0;
if (from_hex_to_i(s, i + 1, 2, val)) { if (from_hex_to_i(s, i + 1, 2, val)) {
// 2 digits hex codes // 2 digits hex codes
result += static_cast<char>(val); result += static_cast<char>(val);
@ -2468,7 +2468,7 @@ inline Error wait_until_socket_is_ready(socket_t sock, time_t sec,
if (poll_res == 0) { return Error::ConnectionTimeout; } if (poll_res == 0) { return Error::ConnectionTimeout; }
if (poll_res > 0 && pfd_read.revents & (POLLIN | POLLOUT)) { if (poll_res > 0 && pfd_read.revents & (POLLIN | POLLOUT)) {
int error = 0; auto error = 0;
socklen_t len = sizeof(error); socklen_t len = sizeof(error);
auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR, auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR,
reinterpret_cast<char *>(&error), &len); reinterpret_cast<char *>(&error), &len);
@ -2500,7 +2500,7 @@ inline Error wait_until_socket_is_ready(socket_t sock, time_t sec,
if (ret == 0) { return Error::ConnectionTimeout; } if (ret == 0) { return Error::ConnectionTimeout; }
if (ret > 0 && (FD_ISSET(sock, &fdsr) || FD_ISSET(sock, &fdsw))) { if (ret > 0 && (FD_ISSET(sock, &fdsr) || FD_ISSET(sock, &fdsw))) {
int error = 0; auto error = 0;
socklen_t len = sizeof(error); socklen_t len = sizeof(error);
auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR, auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR,
reinterpret_cast<char *>(&error), &len); reinterpret_cast<char *>(&error), &len);
@ -2745,7 +2745,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
#endif #endif
if (tcp_nodelay) { if (tcp_nodelay) {
int yes = 1; auto yes = 1;
#ifdef _WIN32 #ifdef _WIN32
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<const char *>(&yes), sizeof(yes)); reinterpret_cast<const char *>(&yes), sizeof(yes));
@ -2758,7 +2758,7 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
if (socket_options) { socket_options(sock); } if (socket_options) { socket_options(sock); }
if (rp->ai_family == AF_INET6) { if (rp->ai_family == AF_INET6) {
int no = 0; auto no = 0;
#ifdef _WIN32 #ifdef _WIN32
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
reinterpret_cast<const char *>(&no), sizeof(no)); reinterpret_cast<const char *>(&no), sizeof(no));
@ -3240,7 +3240,7 @@ inline bool gzip_compressor::compress(const char *data, size_t data_length,
data += strm_.avail_in; data += strm_.avail_in;
auto flush = (last && data_length == 0) ? Z_FINISH : Z_NO_FLUSH; auto flush = (last && data_length == 0) ? Z_FINISH : Z_NO_FLUSH;
int ret = Z_OK; auto ret = Z_OK;
std::array<char, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{}; std::array<char, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{};
do { do {
@ -3284,7 +3284,7 @@ inline bool gzip_decompressor::decompress(const char *data, size_t data_length,
Callback callback) { Callback callback) {
assert(is_valid_); assert(is_valid_);
int ret = Z_OK; auto ret = Z_OK;
do { do {
constexpr size_t max_avail_in = constexpr size_t max_avail_in =
@ -4587,7 +4587,7 @@ inline bool retrieve_root_certs_from_keychain(CFObjectPtr<CFArrayRef> &certs) {
inline bool add_certs_to_x509_store(CFArrayRef certs, X509_STORE *store) { inline bool add_certs_to_x509_store(CFArrayRef certs, X509_STORE *store) {
auto result = false; auto result = false;
for (int i = 0; i < CFArrayGetCount(certs); ++i) { for (auto i = 0; i < CFArrayGetCount(certs); ++i) {
const auto cert = reinterpret_cast<const __SecCertificate *>( const auto cert = reinterpret_cast<const __SecCertificate *>(
CFArrayGetValueAtIndex(certs, i)); CFArrayGetValueAtIndex(certs, i));
@ -4805,7 +4805,7 @@ inline void hosted_at(const std::string &hostname,
const auto &addr = const auto &addr =
*reinterpret_cast<struct sockaddr_storage *>(rp->ai_addr); *reinterpret_cast<struct sockaddr_storage *>(rp->ai_addr);
std::string ip; std::string ip;
int dummy = -1; auto dummy = -1;
if (detail::get_ip_and_port(addr, sizeof(struct sockaddr_storage), ip, if (detail::get_ip_and_port(addr, sizeof(struct sockaddr_storage), ip,
dummy)) { dummy)) {
addrs.push_back(ip); addrs.push_back(ip);
@ -7697,7 +7697,7 @@ bool ssl_connect_or_accept_nonblocking(socket_t sock, SSL *ssl,
U ssl_connect_or_accept, U ssl_connect_or_accept,
time_t timeout_sec, time_t timeout_sec,
time_t timeout_usec) { time_t timeout_usec) {
int res = 0; auto res = 0;
while ((res = ssl_connect_or_accept(ssl)) != 1) { while ((res = ssl_connect_or_accept(ssl)) != 1) {
auto err = SSL_get_error(ssl, res); auto err = SSL_get_error(ssl, res);
switch (err) { switch (err) {
@ -7778,7 +7778,7 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
auto ret = SSL_read(ssl_, ptr, static_cast<int>(size)); auto ret = SSL_read(ssl_, ptr, static_cast<int>(size));
if (ret < 0) { if (ret < 0) {
auto err = SSL_get_error(ssl_, ret); auto err = SSL_get_error(ssl_, ret);
int n = 1000; auto n = 1000;
#ifdef _WIN32 #ifdef _WIN32
while (--n >= 0 && (err == SSL_ERROR_WANT_READ || while (--n >= 0 && (err == SSL_ERROR_WANT_READ ||
(err == SSL_ERROR_SYSCALL && (err == SSL_ERROR_SYSCALL &&
@ -7811,7 +7811,7 @@ inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {
auto ret = SSL_write(ssl_, ptr, static_cast<int>(handle_size)); auto ret = SSL_write(ssl_, ptr, static_cast<int>(handle_size));
if (ret < 0) { if (ret < 0) {
auto err = SSL_get_error(ssl_, ret); auto err = SSL_get_error(ssl_, ret);
int n = 1000; auto n = 1000;
#ifdef _WIN32 #ifdef _WIN32
while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE || while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE ||
(err == SSL_ERROR_SYSCALL && (err == SSL_ERROR_SYSCALL &&