/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
std::size_t asize = a.size();
std::array<uint8_t, N> ba{{0}};
for (std::size_t i = 0; i < asize; i++) {
- ba[i] = a[i] & b[i];
+ ba[i] = uint8_t(a[i] & b[i]);
}
return ba;
}
ba[byteIndex] = one[byteIndex];
++byteIndex;
}
- auto bitIndex = std::min(mask, (uint8_t)(byteIndex * 8));
+ auto bitIndex = std::min(mask, uint8_t(byteIndex * 8));
+ uint8_t bI = uint8_t(bitIndex / 8);
+ uint8_t bM = uint8_t(bitIndex % 8);
// Compute the bit up to which the two byte arrays match in the
// unmatched byte.
// Here the check is bitIndex < mask since the 0th mask entry in
// kMasks array holds the mask for masking the MSb in this byte.
// We could instead make it hold so that no 0th entry masks no
// bits but thats a useless iteration.
- while (bitIndex < mask && ((one[bitIndex / 8] & kMasks[bitIndex % 8]) ==
- (two[bitIndex / 8] & kMasks[bitIndex % 8]))) {
- ba[bitIndex / 8] = one[bitIndex / 8] & kMasks[bitIndex % 8];
+ while (bitIndex < mask &&
+ ((one[bI] & kMasks[bM]) == (two[bI] & kMasks[bM]))) {
+ ba[bI] = uint8_t(one[bI] & kMasks[bM]);
++bitIndex;
+ bI = uint8_t(bitIndex / 8);
+ bM = uint8_t(bitIndex % 8);
}
return {ba, bitIndex};
}
for (std::size_t i = 0; i < len; i++) {
const unsigned char c = src[i];
out[i * 2 + 0] = lut[c >> 4];
- out[i + 2 + 1] = lut[c & 15];
+ out[i * 2 + 1] = lut[c & 15];
}
return out;
}
template <
class IntegralType,
IntegralType DigitCount,
- IntegralType Base = 10,
+ IntegralType Base = IntegralType(10),
bool PrintAllDigits = false,
class = typename std::enable_if<
std::is_integral<IntegralType>::value &&
}
IntegralType powerToPrint = 1;
- for (int i = 1; i < DigitCount; ++i) {
+ for (IntegralType i = 1; i < DigitCount; ++i) {
powerToPrint *= Base;
}
bool found = PrintAllDigits;
while (powerToPrint) {
if (found || powerToPrint <= val) {
- IntegralType value = val / powerToPrint;
+ IntegralType value = IntegralType(val / powerToPrint);
if (Base == 10 || value < 10) {
value += '0';
} else {
value += ('a' - 10);
}
- *(buf++) = value;
+ *(buf++) = char(value);
val %= powerToPrint;
found = true;
}
*(buf++) = '.';
writeIntegerString<uint8_t, 3>(octets[3], &buf);
- return std::string(str, buf - str);
+ return std::string(str, size_t(buf - str));
}
inline std::string fastIpv6ToString(const in6_addr& in6Addr) {
}
}
- return std::string(str, buf - str);
+ return std::string(str, size_t(buf - str));
}
}
}