Skip to content

Commit

Permalink
Merge pull request #219 from antonlindstrom/cleanup/old-style-cast
Browse files Browse the repository at this point in the history
Fix -Wold-style-cast warnings
  • Loading branch information
whoshuu committed Oct 23, 2017
2 parents 27f9649 + 3b76835 commit 436a325
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cpr/timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ long Timeout::Milliseconds() const {
std::to_string(ms.count()) + " ms.");
}

return static_cast<long>(ms.count());
return ms.count();
}

} // namespace cpr
4 changes: 2 additions & 2 deletions cpr/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ std::vector<std::string> split(const std::string& to_split, char delimiter) {
}

size_t writeFunction(void* ptr, size_t size, size_t nmemb, std::string* data) {
data->append((char*) ptr, size * nmemb);
data->append(static_cast<char*>(ptr), size * nmemb);
return size * nmemb;
}

Expand All @@ -71,7 +71,7 @@ std::string urlEncode(const std::string& value) {
continue;
}
// Any other characters are percent-encoded
escaped << '%' << std::setw(2) << std::int32_t((unsigned char) c);
escaped << '%' << std::setw(2) << std::int32_t(static_cast<unsigned char>(c));
}

return escaped.str();
Expand Down
2 changes: 1 addition & 1 deletion test/post_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST(UrlEncodedPostTests, UrlPostAddPayloadPair) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "1"}};
payload.AddPair({"y", "2"});
auto response = cpr::Post(url, Payload(payload));
auto response = cpr::Post(url, payload);
auto expected_text = std::string{"{\n"
" \"x\": 1,\n"
" \"y\": 2,\n"
Expand Down
14 changes: 7 additions & 7 deletions test/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static int basicCookies(struct mg_connection* conn) {
mg_send_header(conn, "content-type", "text/html");
time_t t = time(NULL) + 5; // Valid for 1 hour
char expire[100], expire_epoch[100];
snprintf(expire_epoch, sizeof(expire_epoch), "%lu", (unsigned long) t);
snprintf(expire_epoch, sizeof(expire_epoch), "%lu", static_cast<unsigned long>(t));
strftime(expire, sizeof(expire), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
std::string cookie{"cookie=chocolate; expires=\"" + std::string{expire} + "\"; http-only;"};
std::string cookie2{"icecream=vanilla; expires=\"" + std::string{expire} + "\"; http-only;"};
Expand All @@ -115,7 +115,7 @@ static int v1Cookies(struct mg_connection* conn) {
mg_send_header(conn, "content-type", "text/html");
time_t t = time(NULL) + 5; // Valid for 1 hour
char expire[100], expire_epoch[100];
snprintf(expire_epoch, sizeof(expire_epoch), "%lu", (unsigned long) t);
snprintf(expire_epoch, sizeof(expire_epoch), "%lu", static_cast<unsigned long>(t));
strftime(expire, sizeof(expire), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
std::string v1cookie{"cookie=\"value with spaces (v1 cookie)\"; expires=\"" +
std::string{expire} + "\"; http-only;"};
Expand Down Expand Up @@ -342,7 +342,7 @@ static int formPost(struct mg_connection* conn) {
auto read_len = mg_parse_multipart(content, content_len,
name, sizeof(name),
filename, sizeof(filename),
(const char**) &data, &data_len);
const_cast<const char**>(&data), &data_len);
if (read_len == 0) {
delete[] data;
break;
Expand All @@ -356,7 +356,7 @@ static int formPost(struct mg_connection* conn) {
break;
}

forms[name] = std::string{data, (unsigned long) data_len};
forms[name] = std::string{data, static_cast<unsigned long>(data_len)};
}

mg_send_status(conn, 201);
Expand Down Expand Up @@ -540,9 +540,9 @@ static int evHandler(struct mg_connection* conn, enum mg_event ev) {
} else if (Url{conn->uri} == "/timeout.html") {
return timeout(conn);
} else if (Url{conn->uri} == "/low_speed.html") {
return lowSpeed(conn);
return lowSpeed(conn);
} else if (Url{conn->uri} == "/low_speed_bytes.html") {
return lowSpeedBytes(conn);
return lowSpeedBytes(conn);
} else if (Url{conn->uri} == "/basic_cookies.html") {
return basicCookies(conn);
} else if (Url{conn->uri} == "/check_cookies.html") {
Expand Down Expand Up @@ -684,7 +684,7 @@ std::string base64_decode(std::string const& encoded_string) {
}

static int lowercase(const char *s) {
return tolower(* (const unsigned char *) s);
return tolower(* reinterpret_cast<const unsigned char *>(s));
}

static int mg_strncasecmp(const char *s1, const char *s2, size_t len) {
Expand Down

0 comments on commit 436a325

Please sign in to comment.