Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/time_zone_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <limits>
#include <string>
#include <vector>
#if !HAS_STRPTIME
#if !defined(HAS_STRPTIME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if !defined(HAS_STRPTIME) is not the same as #if !HAS_STRPTIME when HAS_STRPTIME=0, which is intended to be a valid way to say "I don't have strptime()".

I see that we have #if defined(HAS_STRPTIME) && HAS_STRPTIME in another place (presumably to workaround the same warning), so I suggest we rework these new changes with the negation of that.

[All that said, I'm not a fan of -Wundef, but I guess that's a lost argument.]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#331 addresses this comment.

#include <iomanip>
#include <sstream>
#endif
Expand All @@ -52,7 +52,7 @@ namespace detail {

namespace {

#if !HAS_STRPTIME
#if !defined(HAS_STRPTIME)
// Build a strptime() using C++11's std::get_time().
char* strptime(const char* s, const char* fmt, std::tm* tm) {
std::istringstream input(s);
Expand Down
23 changes: 11 additions & 12 deletions src/time_zone_name_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <algorithm>
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <string>
Expand Down Expand Up @@ -129,15 +130,14 @@ std::string Utf16ToUtf8(const wchar_t* ptr, size_t size) {
}
const int chars_len = static_cast<int>(size);
std::string result;
std::int32_t len = std::max<std::int32_t>(
static_cast<std::int32_t>(std::min<size_t>(
result.capacity(), std::numeric_limits<std::int32_t>::max())),
1);
std::size_t len = std::max<std::size_t>(
std::min<size_t>(result.capacity(), std::numeric_limits<int>::max()), 1);
do {
result.resize(len);
// TODO: Switch to std::string::data() when we require C++17 or higher.
len = ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, ptr, chars_len,
&result[0], len, nullptr, nullptr);
len = static_cast<std::size_t>(::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, ptr, chars_len, &result[0],
static_cast<int>(len), nullptr, nullptr));
} while (len > result.size());
result.resize(len);
return result;
Expand All @@ -157,15 +157,14 @@ std::string GetWindowsLocalTimeZone() {
}

std::wstring result;
std::int32_t len = std::max<std::int32_t>(
static_cast<std::int32_t>(std::min<size_t>(
result.capacity(), std::numeric_limits<std::int32_t>::max())),
1);
std::size_t len = std::max<std::size_t>(
std::min<size_t>(result.capacity(), std::numeric_limits<int>::max()), 1);
for (;;) {
UErrorCode status = U_ZERO_ERROR;
result.resize(len);
len = getTimeZoneIDForWindowsID(info.TimeZoneKeyName, -1, nullptr,
&result[0], len, &status);
len = static_cast<std::size_t>(
getTimeZoneIDForWindowsID(info.TimeZoneKeyName, -1, nullptr, &result[0],
static_cast<int>(len), &status));
if (U_SUCCESS(status)) {
return Utf16ToUtf8(result.data(), len);
}
Expand Down