Fix MSVC warnings about value truncations, webrtc/base/ edition.
BUG=chromium:81439
TEST=none
R=henrike@webrtc.org, marpan@google.com
Review URL: https://webrtc-codereview.appspot.com/20249004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@7143 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/base/httpclient.cc b/base/httpclient.cc
index 6256772..0bf3880 100644
--- a/base/httpclient.cc
+++ b/base/httpclient.cc
@@ -91,7 +91,7 @@
time_t u_temp;
// Current time
- size_t now = time(0);
+ time_t now = time(0);
HttpAttributeList cache_control;
if (t.response.hasHeader(HH_CACHE_CONTROL, &s_temp)) {
@@ -113,7 +113,7 @@
apparent_age = response_time - date;
}
- size_t corrected_received_age = apparent_age;
+ time_t corrected_received_age = apparent_age;
size_t i_temp;
if (t.response.hasHeader(HH_AGE, &s_temp)
&& HttpStringToUInt(s_temp, (&i_temp))) {
@@ -121,13 +121,13 @@
corrected_received_age = stdmax(apparent_age, u_temp);
}
- size_t response_delay = response_time - request_time;
- size_t corrected_initial_age = corrected_received_age + response_delay;
- size_t resident_time = now - response_time;
- size_t current_age = corrected_initial_age + resident_time;
+ time_t response_delay = response_time - request_time;
+ time_t corrected_initial_age = corrected_received_age + response_delay;
+ time_t resident_time = now - response_time;
+ time_t current_age = corrected_initial_age + resident_time;
// Compute lifetime of document
- size_t lifetime;
+ time_t lifetime;
if (HttpHasAttribute(cache_control, "max-age", &s_temp)) {
lifetime = atoi(s_temp.c_str());
} else if (t.response.hasHeader(HH_EXPIRES, &s_temp)
diff --git a/base/httpcommon.cc b/base/httpcommon.cc
index 569b7b3..561d2f4 100644
--- a/base/httpcommon.cc
+++ b/base/httpcommon.cc
@@ -364,7 +364,7 @@
case 'C': tval.tm_mon = 11; break;
}
tval.tm_year -= 1900;
- size_t gmt, non_gmt = mktime(&tval);
+ time_t gmt, non_gmt = mktime(&tval);
if ((zone[0] == '+') || (zone[0] == '-')) {
if (!isdigit(zone[1]) || !isdigit(zone[2])
|| !isdigit(zone[3]) || !isdigit(zone[4])) {
@@ -383,7 +383,7 @@
}
// TODO: Android should support timezone, see b/2441195
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID) || defined(BSD)
- tm *tm_for_timezone = localtime((time_t *)&gmt);
+ tm *tm_for_timezone = localtime(&gmt);
*seconds = gmt + tm_for_timezone->tm_gmtoff;
#else
*seconds = gmt - timezone;
diff --git a/base/socketadapters.cc b/base/socketadapters.cc
index 1cdd1bc..137597f 100644
--- a/base/socketadapters.cc
+++ b/base/socketadapters.cc
@@ -749,7 +749,7 @@
}
}
-void AsyncSocksProxyServerSocket::SendHelloReply(int method) {
+void AsyncSocksProxyServerSocket::SendHelloReply(uint8 method) {
ByteBuffer response;
response.WriteUInt8(5); // Socks Version
response.WriteUInt8(method); // Auth method
@@ -773,7 +773,7 @@
state_ = SS_CONNECT;
}
-void AsyncSocksProxyServerSocket::SendAuthReply(int result) {
+void AsyncSocksProxyServerSocket::SendAuthReply(uint8 result) {
ByteBuffer response;
response.WriteUInt8(1); // Negotiation Version
response.WriteUInt8(result);
diff --git a/base/socketadapters.h b/base/socketadapters.h
index 3292df2..ddf4f18 100644
--- a/base/socketadapters.h
+++ b/base/socketadapters.h
@@ -195,9 +195,9 @@
void DirectSend(const ByteBuffer& buf);
void HandleHello(ByteBuffer* request);
- void SendHelloReply(int method);
+ void SendHelloReply(uint8 method);
void HandleAuth(ByteBuffer* request);
- void SendAuthReply(int result);
+ void SendAuthReply(uint8 result);
void HandleConnect(ByteBuffer* request);
virtual void SendConnectResult(int result, const SocketAddress& addr);
diff --git a/base/socketaddress.cc b/base/socketaddress.cc
index e6717e4..b15c0c4 100644
--- a/base/socketaddress.cc
+++ b/base/socketaddress.cc
@@ -121,7 +121,7 @@
void SocketAddress::SetPort(int port) {
ASSERT((0 <= port) && (port < 65536));
- port_ = port;
+ port_ = static_cast<uint16>(port);
}
uint32 SocketAddress::ip() const {
@@ -279,9 +279,9 @@
}
static size_t ToSockAddrStorageHelper(sockaddr_storage* addr,
- IPAddress ip, int port, int scope_id) {
+ IPAddress ip, uint16 port, int scope_id) {
memset(addr, 0, sizeof(sockaddr_storage));
- addr->ss_family = ip.family();
+ addr->ss_family = static_cast<unsigned short>(ip.family());
if (addr->ss_family == AF_INET6) {
sockaddr_in6* saddr = reinterpret_cast<sockaddr_in6*>(addr);
saddr->sin6_addr = ip.ipv6_address();
diff --git a/base/urlencode.cc b/base/urlencode.cc
index b152829..8dc185d 100644
--- a/base/urlencode.cc
+++ b/base/urlencode.cc
@@ -15,9 +15,9 @@
static int HexPairValue(const char * code) {
int value = 0;
- const char * pch = code;
- for (;;) {
- int digit = *pch++;
+ for (const char * pch = code; pch < code + 2; ++pch) {
+ value <<= 4;
+ int digit = *pch;
if (digit >= '0' && digit <= '9') {
value += digit - '0';
}
@@ -30,10 +30,8 @@
else {
return -1;
}
- if (pch == code + 2)
- return value;
- value <<= 4;
}
+ return value;
}
static int InternalUrlDecode(const char *source, char *dest,
@@ -53,7 +51,7 @@
if (source[1] && source[2]) {
int value = HexPairValue(source + 1);
if (value >= 0) {
- *(dest++) = value;
+ *(dest++) = static_cast<char>(value);
source += 2;
}
else {