Fix sign conversion warnings
This commit is contained in:
@@ -46,7 +46,7 @@ namespace {
|
||||
std::string sanitize(const std::string &s) {
|
||||
std::string result;
|
||||
for (std::string::const_iterator i = s.begin(), end = s.end(); i != end; ++i)
|
||||
result.push_back(*i & 0xff);
|
||||
result.push_back(*i & static_cast<char>(0xff));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,10 +80,10 @@ std::string OutputRedirect::restore_and_read() {
|
||||
return content; // Already read.
|
||||
enum { BUFFER_SIZE = 4096 };
|
||||
char buffer[BUFFER_SIZE];
|
||||
std::streamsize count = 0;
|
||||
std::size_t count = 0;
|
||||
do {
|
||||
count = read_end_.read(buffer, BUFFER_SIZE);
|
||||
content.append(buffer, static_cast<std::size_t>(count));
|
||||
content.append(buffer, count);
|
||||
} while (count != 0);
|
||||
read_end_.close();
|
||||
return content;
|
||||
@@ -91,8 +91,7 @@ std::string OutputRedirect::restore_and_read() {
|
||||
|
||||
std::string read(File &f, std::size_t count) {
|
||||
std::string buffer(count, '\0');
|
||||
std::streamsize n = 0;
|
||||
std::size_t offset = 0;
|
||||
std::size_t n = 0, offset = 0;
|
||||
do {
|
||||
n = f.read(&buffer[offset], count - offset);
|
||||
// We can't read more than size_t bytes since count has type size_t.
|
||||
|
||||
@@ -277,8 +277,7 @@ TEST(FileTest, Size) {
|
||||
write_file("test", content);
|
||||
File f("test", File::RDONLY);
|
||||
EXPECT_GE(f.size(), 0);
|
||||
fmt::ULongLong file_size = f.size();
|
||||
EXPECT_EQ(content.size(), file_size);
|
||||
EXPECT_EQ(content.size(), static_cast<fmt::ULongLong>(f.size()));
|
||||
#ifdef _WIN32
|
||||
fmt::MemoryWriter message;
|
||||
fmt::internal::format_windows_error(
|
||||
@@ -308,7 +307,7 @@ TEST(FileTest, ReadRetry) {
|
||||
write_end.write("test", SIZE);
|
||||
write_end.close();
|
||||
char buffer[SIZE];
|
||||
std::streamsize count = 0;
|
||||
std::size_t count = 0;
|
||||
EXPECT_RETRY(count = read_end.read(buffer, SIZE),
|
||||
read, "cannot read from file");
|
||||
EXPECT_EQ_POSIX(static_cast<std::streamsize>(SIZE), count);
|
||||
@@ -318,7 +317,7 @@ TEST(FileTest, WriteRetry) {
|
||||
File read_end, write_end;
|
||||
File::pipe(read_end, write_end);
|
||||
enum { SIZE = 4 };
|
||||
std::streamsize count = 0;
|
||||
std::size_t count = 0;
|
||||
EXPECT_RETRY(count = write_end.write("test", SIZE),
|
||||
write, "cannot write to file");
|
||||
write_end.close();
|
||||
|
||||
@@ -69,7 +69,7 @@ void write(File &f, fmt::StringRef s) {
|
||||
std::size_t num_chars_left = s.size();
|
||||
const char *ptr = s.data();
|
||||
do {
|
||||
std::streamsize count = f.write(ptr, num_chars_left);
|
||||
std::size_t count = f.write(ptr, num_chars_left);
|
||||
ptr += count;
|
||||
// We can't write more than size_t bytes since num_chars_left
|
||||
// has type size_t.
|
||||
@@ -236,20 +236,20 @@ File OpenBufferedFile(int &fd) {
|
||||
}
|
||||
|
||||
TEST(FileTest, MoveFromTemporaryInCtor) {
|
||||
int fd = 0xdeadbeef;
|
||||
int fd = 0xdead;
|
||||
File f(OpenBufferedFile(fd));
|
||||
EXPECT_EQ(fd, f.descriptor());
|
||||
}
|
||||
|
||||
TEST(FileTest, MoveFromTemporaryInAssignment) {
|
||||
int fd = 0xdeadbeef;
|
||||
int fd = 0xdead;
|
||||
File f;
|
||||
f = OpenBufferedFile(fd);
|
||||
EXPECT_EQ(fd, f.descriptor());
|
||||
}
|
||||
|
||||
TEST(FileTest, MoveFromTemporaryInAssignmentClosesFile) {
|
||||
int fd = 0xdeadbeef;
|
||||
int fd = 0xdead;
|
||||
File f = open_file();
|
||||
int old_fd = f.descriptor();
|
||||
f = OpenBufferedFile(fd);
|
||||
|
||||
@@ -292,21 +292,21 @@ SPECIALIZE_MAKE_SIGNED(fmt::ULongLong, fmt::LongLong);
|
||||
// Test length format specifier ``length_spec``.
|
||||
template <typename T, typename U>
|
||||
void TestLength(const char *length_spec, U value) {
|
||||
fmt::LongLong signed_value = value;
|
||||
fmt::ULongLong unsigned_value = value;
|
||||
fmt::LongLong signed_value = 0;
|
||||
fmt::ULongLong unsigned_value = 0;
|
||||
// Apply integer promotion to the argument.
|
||||
fmt::ULongLong max = std::numeric_limits<U>::max();
|
||||
using fmt::internal::check;
|
||||
if (check(max <= static_cast<unsigned>(std::numeric_limits<int>::max()))) {
|
||||
signed_value = static_cast<int>(value);
|
||||
unsigned_value = static_cast<int>(value);
|
||||
unsigned_value = static_cast<unsigned>(value);
|
||||
} else if (check(max <= std::numeric_limits<unsigned>::max())) {
|
||||
signed_value = static_cast<unsigned>(value);
|
||||
unsigned_value = static_cast<unsigned>(value);
|
||||
}
|
||||
using fmt::internal::MakeUnsigned;
|
||||
if (sizeof(U) <= sizeof(int) && sizeof(int) < sizeof(T)) {
|
||||
signed_value = value;
|
||||
signed_value = static_cast<fmt::LongLong>(value);
|
||||
unsigned_value = static_cast<typename MakeUnsigned<unsigned>::Type>(value);
|
||||
} else {
|
||||
signed_value = static_cast<typename MakeSigned<T>::Type>(value);
|
||||
@@ -382,7 +382,7 @@ TEST(PrintfTest, Bool) {
|
||||
TEST(PrintfTest, Int) {
|
||||
EXPECT_PRINTF("-42", "%d", -42);
|
||||
EXPECT_PRINTF("-42", "%i", -42);
|
||||
unsigned u = -42;
|
||||
unsigned u = -42u;
|
||||
EXPECT_PRINTF(fmt::format("{}", u), "%u", -42);
|
||||
EXPECT_PRINTF(fmt::format("{:o}", u), "%o", -42);
|
||||
EXPECT_PRINTF(fmt::format("{:x}", u), "%x", -42);
|
||||
|
||||
@@ -332,8 +332,9 @@ TEST(MemoryBufferTest, Grow) {
|
||||
void grow(std::size_t size) { Base::grow(size); }
|
||||
} buffer((Allocator(&alloc)));
|
||||
buffer.resize(7);
|
||||
using fmt::internal::to_unsigned;
|
||||
for (int i = 0; i < 7; ++i)
|
||||
buffer[i] = i * i;
|
||||
buffer[to_unsigned(i)] = i * i;
|
||||
EXPECT_EQ(10u, buffer.capacity());
|
||||
int mem[20];
|
||||
mem[7] = 0xdead;
|
||||
@@ -342,7 +343,7 @@ TEST(MemoryBufferTest, Grow) {
|
||||
EXPECT_EQ(20u, buffer.capacity());
|
||||
// Check if size elements have been copied
|
||||
for (int i = 0; i < 7; ++i)
|
||||
EXPECT_EQ(i * i, buffer[i]);
|
||||
EXPECT_EQ(i * i, buffer[to_unsigned(i)]);
|
||||
// and no more than that.
|
||||
EXPECT_EQ(0xdead, buffer[7]);
|
||||
EXPECT_CALL(alloc, deallocate(mem, 20));
|
||||
|
||||
Reference in New Issue
Block a user