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
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;
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));
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);
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);
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) {
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) {
}
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];
}
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];
#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;
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) {
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];