Commit 6fc7a48c authored by Ranjeeth Dasineni's avatar Ranjeeth Dasineni Committed by Anton Likhtarov

rfc : -Wshorten-64-to-32 warnings in folly liger dependencies

Summary:
This is not a fix but me seeking advice here. The context here is that in liger (our common network
stack for mobile platforms), we saw bugs due to truncation and want to enable these warnings. To find those in our code,
I had to first resolve the folly ones. I just got around by making the truncation explicit so that I can get to real errors.
Ideally I would like owners to examine each case and fix the original/accept the explicit truncate if its intended. Let me
know what you think. The last (least preferred) is for us to keep this as a liger only change. We have a couple of ways to
do that but it would be nice to fix.

N.B : this covers only liger dependencies

Test Plan: errors resolved after these changes.

Reviewed By: njormrod@fb.com

Subscribers: trunkagent, doug, shilin, njormrod, seanc, pgriess

FB internal diff: D1509355
parent 54ab6858
......@@ -153,10 +153,10 @@ digitsEnough() {
return ceil((double(sizeof(IntegerType) * CHAR_BIT) * M_LN2) / M_LN10);
}
inline unsigned int
unsafeTelescope128(char * buffer, unsigned int room, unsigned __int128 x) {
inline size_t
unsafeTelescope128(char * buffer, size_t room, unsigned __int128 x) {
typedef unsigned __int128 Usrc;
unsigned int p = room - 1;
size_t p = room - 1;
while (x >= (Usrc(1) << 64)) { // Using 128-bit division while needed
const auto y = x / 10;
......@@ -348,7 +348,7 @@ void
toAppend(__int128 value, Tgt * result) {
typedef unsigned __int128 Usrc;
char buffer[detail::digitsEnough<unsigned __int128>() + 1];
unsigned int p;
size_t p;
if (value < 0) {
p = detail::unsafeTelescope128(buffer, sizeof(buffer), Usrc(-value));
......@@ -364,7 +364,7 @@ template <class Tgt>
void
toAppend(unsigned __int128 value, Tgt * result) {
char buffer[detail::digitsEnough<unsigned __int128>()];
unsigned int p;
size_t p;
p = detail::unsafeTelescope128(buffer, sizeof(buffer), value);
......@@ -1230,8 +1230,9 @@ to(StringPiece *const src) {
FOLLY_RANGE_CHECK(!src->empty(), "No digits found in input string");
int length;
auto result = conv.StringToDouble(src->data(), src->size(),
&length); // processed char count
auto result = conv.StringToDouble(src->data(),
static_cast<int>(src->size()),
&length); // processed char count
if (!std::isnan(result)) {
src->advance(length);
......
......@@ -326,7 +326,7 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) {
int padRemaining = 0;
if (arg.width != FormatArg::kDefaultWidth && val.size() < arg.width) {
char fill = arg.fill == FormatArg::kDefaultFill ? ' ' : arg.fill;
int padChars = arg.width - val.size();
int padChars = static_cast<int> (arg.width - val.size());
memset(padBuf, fill, std::min(padBufSize, padChars));
switch (arg.align) {
......@@ -634,7 +634,7 @@ class FormatValue<double> {
DoubleToStringConverter::kMaxFixedDigitsAfterPoint),
(8 + DoubleToStringConverter::kMaxExponentialDigits),
(7 + DoubleToStringConverter::kMaxPrecisionDigits)})];
StringBuilder builder(buf + 1, sizeof(buf) - 1);
StringBuilder builder(buf + 1, static_cast<int> (sizeof(buf) - 1));
char plusSign;
switch (arg.sign) {
......
......@@ -217,11 +217,11 @@ inline uint32_t fnv32(const char* s,
}
inline uint32_t fnv32_buf(const void* buf,
int n,
size_t n,
uint32_t hash = FNV_32_HASH_START) {
const char* char_buf = reinterpret_cast<const char*>(buf);
for (int i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
hash += (hash << 1) + (hash << 4) + (hash << 7) +
(hash << 8) + (hash << 24);
hash ^= char_buf[i];
......@@ -246,11 +246,11 @@ inline uint64_t fnv64(const char* s,
}
inline uint64_t fnv64_buf(const void* buf,
int n,
size_t n,
uint64_t hash = FNV_64_HASH_START) {
const char* char_buf = reinterpret_cast<const char*>(buf);
for (int i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
hash += (hash << 1) + (hash << 4) + (hash << 5) + (hash << 7) +
(hash << 8) + (hash << 40);
hash ^= char_buf[i];
......@@ -269,11 +269,11 @@ inline uint64_t fnv64(const std::string& str,
#define get16bits(d) (*((const uint16_t*) (d)))
inline uint32_t hsieh_hash32_buf(const void* buf, int len) {
inline uint32_t hsieh_hash32_buf(const void* buf, size_t len) {
const char* s = reinterpret_cast<const char*>(buf);
uint32_t hash = len;
uint32_t hash = static_cast<uint32_t>(len);
uint32_t tmp;
int rem;
size_t rem;
if (len <= 0 || buf == 0) {
return 0;
......
......@@ -320,8 +320,8 @@ void internalSplit(DelimT delim, StringPiece sp, OutputIterator out,
ignoreEmpty);
}
int tokenStartPos = 0;
int tokenSize = 0;
size_t tokenStartPos = 0;
size_t tokenSize = 0;
for (size_t i = 0; i <= strSize - dSize; ++i) {
if (atDelim(&s[i], delim)) {
if (!ignoreEmpty || tokenSize > 0) {
......@@ -615,7 +615,7 @@ bool hexlify(const InputString& input, OutputString& output,
if (!append_output) output.clear();
static char hexValues[] = "0123456789abcdef";
int j = output.size();
auto j = output.size();
output.resize(2 * input.size() + output.size());
for (size_t i = 0; i < input.size(); ++i) {
int ch = input[i];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment