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@7143 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrike@webrtc.org
2014-09-10 22:10:24 +00:00
parent 3472dcd7b0
commit 1711104b8a
6 changed files with 21 additions and 23 deletions

View File

@@ -91,7 +91,7 @@ HttpCacheState HttpGetCacheState(const HttpTransaction& t) {
time_t u_temp; time_t u_temp;
// Current time // Current time
size_t now = time(0); time_t now = time(0);
HttpAttributeList cache_control; HttpAttributeList cache_control;
if (t.response.hasHeader(HH_CACHE_CONTROL, &s_temp)) { if (t.response.hasHeader(HH_CACHE_CONTROL, &s_temp)) {
@@ -113,7 +113,7 @@ HttpCacheState HttpGetCacheState(const HttpTransaction& t) {
apparent_age = response_time - date; apparent_age = response_time - date;
} }
size_t corrected_received_age = apparent_age; time_t corrected_received_age = apparent_age;
size_t i_temp; size_t i_temp;
if (t.response.hasHeader(HH_AGE, &s_temp) if (t.response.hasHeader(HH_AGE, &s_temp)
&& HttpStringToUInt(s_temp, (&i_temp))) { && HttpStringToUInt(s_temp, (&i_temp))) {
@@ -121,13 +121,13 @@ HttpCacheState HttpGetCacheState(const HttpTransaction& t) {
corrected_received_age = stdmax(apparent_age, u_temp); corrected_received_age = stdmax(apparent_age, u_temp);
} }
size_t response_delay = response_time - request_time; time_t response_delay = response_time - request_time;
size_t corrected_initial_age = corrected_received_age + response_delay; time_t corrected_initial_age = corrected_received_age + response_delay;
size_t resident_time = now - response_time; time_t resident_time = now - response_time;
size_t current_age = corrected_initial_age + resident_time; time_t current_age = corrected_initial_age + resident_time;
// Compute lifetime of document // Compute lifetime of document
size_t lifetime; time_t lifetime;
if (HttpHasAttribute(cache_control, "max-age", &s_temp)) { if (HttpHasAttribute(cache_control, "max-age", &s_temp)) {
lifetime = atoi(s_temp.c_str()); lifetime = atoi(s_temp.c_str());
} else if (t.response.hasHeader(HH_EXPIRES, &s_temp) } else if (t.response.hasHeader(HH_EXPIRES, &s_temp)

View File

@@ -364,7 +364,7 @@ bool HttpDateToSeconds(const std::string& date, time_t* seconds) {
case 'C': tval.tm_mon = 11; break; case 'C': tval.tm_mon = 11; break;
} }
tval.tm_year -= 1900; tval.tm_year -= 1900;
size_t gmt, non_gmt = mktime(&tval); time_t gmt, non_gmt = mktime(&tval);
if ((zone[0] == '+') || (zone[0] == '-')) { if ((zone[0] == '+') || (zone[0] == '-')) {
if (!isdigit(zone[1]) || !isdigit(zone[2]) if (!isdigit(zone[1]) || !isdigit(zone[2])
|| !isdigit(zone[3]) || !isdigit(zone[4])) { || !isdigit(zone[3]) || !isdigit(zone[4])) {
@@ -383,7 +383,7 @@ bool HttpDateToSeconds(const std::string& date, time_t* seconds) {
} }
// TODO: Android should support timezone, see b/2441195 // TODO: Android should support timezone, see b/2441195
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID) || defined(BSD) #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; *seconds = gmt + tm_for_timezone->tm_gmtoff;
#else #else
*seconds = gmt - timezone; *seconds = gmt - timezone;

View File

@@ -749,7 +749,7 @@ void AsyncSocksProxyServerSocket::HandleHello(ByteBuffer* request) {
} }
} }
void AsyncSocksProxyServerSocket::SendHelloReply(int method) { void AsyncSocksProxyServerSocket::SendHelloReply(uint8 method) {
ByteBuffer response; ByteBuffer response;
response.WriteUInt8(5); // Socks Version response.WriteUInt8(5); // Socks Version
response.WriteUInt8(method); // Auth method response.WriteUInt8(method); // Auth method
@@ -773,7 +773,7 @@ void AsyncSocksProxyServerSocket::HandleAuth(ByteBuffer* request) {
state_ = SS_CONNECT; state_ = SS_CONNECT;
} }
void AsyncSocksProxyServerSocket::SendAuthReply(int result) { void AsyncSocksProxyServerSocket::SendAuthReply(uint8 result) {
ByteBuffer response; ByteBuffer response;
response.WriteUInt8(1); // Negotiation Version response.WriteUInt8(1); // Negotiation Version
response.WriteUInt8(result); response.WriteUInt8(result);

View File

@@ -195,9 +195,9 @@ class AsyncSocksProxyServerSocket : public AsyncProxyServerSocket {
void DirectSend(const ByteBuffer& buf); void DirectSend(const ByteBuffer& buf);
void HandleHello(ByteBuffer* request); void HandleHello(ByteBuffer* request);
void SendHelloReply(int method); void SendHelloReply(uint8 method);
void HandleAuth(ByteBuffer* request); void HandleAuth(ByteBuffer* request);
void SendAuthReply(int result); void SendAuthReply(uint8 result);
void HandleConnect(ByteBuffer* request); void HandleConnect(ByteBuffer* request);
virtual void SendConnectResult(int result, const SocketAddress& addr); virtual void SendConnectResult(int result, const SocketAddress& addr);

View File

@@ -121,7 +121,7 @@ void SocketAddress::SetResolvedIP(const IPAddress& ip) {
void SocketAddress::SetPort(int port) { void SocketAddress::SetPort(int port) {
ASSERT((0 <= port) && (port < 65536)); ASSERT((0 <= port) && (port < 65536));
port_ = port; port_ = static_cast<uint16>(port);
} }
uint32 SocketAddress::ip() const { uint32 SocketAddress::ip() const {
@@ -279,9 +279,9 @@ bool SocketAddress::FromSockAddr(const sockaddr_in& saddr) {
} }
static size_t ToSockAddrStorageHelper(sockaddr_storage* addr, 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)); 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) { if (addr->ss_family == AF_INET6) {
sockaddr_in6* saddr = reinterpret_cast<sockaddr_in6*>(addr); sockaddr_in6* saddr = reinterpret_cast<sockaddr_in6*>(addr);
saddr->sin6_addr = ip.ipv6_address(); saddr->sin6_addr = ip.ipv6_address();

View File

@@ -15,9 +15,9 @@
static int HexPairValue(const char * code) { static int HexPairValue(const char * code) {
int value = 0; int value = 0;
const char * pch = code; for (const char * pch = code; pch < code + 2; ++pch) {
for (;;) { value <<= 4;
int digit = *pch++; int digit = *pch;
if (digit >= '0' && digit <= '9') { if (digit >= '0' && digit <= '9') {
value += digit - '0'; value += digit - '0';
} }
@@ -30,10 +30,8 @@ static int HexPairValue(const char * code) {
else { else {
return -1; return -1;
} }
if (pch == code + 2)
return value;
value <<= 4;
} }
return value;
} }
static int InternalUrlDecode(const char *source, char *dest, static int InternalUrlDecode(const char *source, char *dest,
@@ -53,7 +51,7 @@ static int InternalUrlDecode(const char *source, char *dest,
if (source[1] && source[2]) { if (source[1] && source[2]) {
int value = HexPairValue(source + 1); int value = HexPairValue(source + 1);
if (value >= 0) { if (value >= 0) {
*(dest++) = value; *(dest++) = static_cast<char>(value);
source += 2; source += 2;
} }
else { else {