From 3f574c16117d8fe54bb558890e9d29ac561c2305 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 17 Feb 2015 10:11:42 +0800 Subject: [PATCH 1/2] Silence warnings on Windows --- format.cc | 6 +++--- posix.cc | 10 +++++----- test/util-test.cc | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/format.cc b/format.cc index 1a6e4e22..843d4833 100644 --- a/format.cc +++ b/format.cc @@ -488,10 +488,10 @@ FMT_FUNC int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) { } FMT_FUNC void fmt::WindowsError::init( - int error_code, StringRef format_str, ArgList args) { - error_code_ = error_code; + int err_code, StringRef format_str, ArgList args) { + error_code_ = err_code; MemoryWriter w; - internal::format_windows_error(w, error_code, format(format_str, args)); + internal::format_windows_error(w, err_code, format(format_str, args)); std::runtime_error &base = *this; base = std::runtime_error(w.str()); } diff --git a/posix.cc b/posix.cc index b4893cd6..d8f9bb62 100644 --- a/posix.cc +++ b/posix.cc @@ -134,13 +134,13 @@ void fmt::File::close() { fmt::LongLong fmt::File::size() const { #ifdef _WIN32 - LARGE_INTEGER size = {}; + LARGE_INTEGER filesize = {}; HANDLE handle = reinterpret_cast(_get_osfhandle(fd_)); - if (!FMT_SYSTEM(GetFileSizeEx(handle, &size))) + if (!FMT_SYSTEM(GetFileSizeEx(handle, &filesize))) throw WindowsError(GetLastError(), "cannot get file size"); - FMT_STATIC_ASSERT(sizeof(fmt::LongLong) >= sizeof(size.QuadPart), + FMT_STATIC_ASSERT(sizeof(fmt::LongLong) >= sizeof(filesize.QuadPart), "return type of File::size is not large enough"); - return size.QuadPart; + return filesize.QuadPart; #else typedef struct stat Stat; Stat file_stat = Stat(); @@ -228,7 +228,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) { long fmt::getpagesize() { #ifdef _WIN32 - SYSTEM_INFO si = {}; + SYSTEM_INFO si; GetSystemInfo(&si); return si.dwPageSize; #else diff --git a/test/util-test.cc b/test/util-test.cc index fd295525..8b8a20a1 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -699,9 +699,8 @@ void test_count_digits() { } TEST(UtilTest, StringRef) { - char space[100]; - std::strcpy(space, "some string"); - EXPECT_EQ(sizeof("some string") - 1, StringRef(space).size()); + char space[100] = "some string"; + EXPECT_EQ(std::strlen(space), StringRef(space).size()); } TEST(UtilTest, CountDigits) { From 5b0a9bbe852c6912f83f1924c095346fed8dc3ef Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 17 Feb 2015 06:45:45 -0800 Subject: [PATCH 2/2] Improve StringRef test --- test/util-test.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/util-test.cc b/test/util-test.cc index 8b8a20a1..59dfddff 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -699,8 +699,11 @@ void test_count_digits() { } TEST(UtilTest, StringRef) { - char space[100] = "some string"; - EXPECT_EQ(std::strlen(space), StringRef(space).size()); + // Test that StringRef::size() returns string length, not buffer size. + enum {BUFFER_SIZE = 100}; + char str[BUFFER_SIZE] = "some string"; + EXPECT_EQ(std::strlen(str), StringRef(str).size()); + EXPECT_LT(std::strlen(str), BUFFER_SIZE); } TEST(UtilTest, CountDigits) {