Commit 667e13e2 authored by jgruber's avatar jgruber Committed by Commit Bot

[intl] Use std::string backing stores in tz cache

Long timezone names overflowed the timezone cache which had a static
length of 100. This uses dynamically allocated std::strings as backing
stores instead.

Bug: chromium:842085
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I3da474c8b7c530b0933018c6239021979c320043
Reviewed-on: https://chromium-review.googlesource.com/1064111Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53243}
parent 2b0c9fbb
......@@ -158,11 +158,13 @@ void ToDateString(double time_val, Vector<char> str, DateCache* date_cache,
kShortMonths[month], day, year);
return;
case kTimeOnly:
// TODO(842085): str may be silently truncated.
SNPrintF(str, "%02d:%02d:%02d GMT%c%02d%02d (%s)", hour, min, sec,
(timezone_offset < 0) ? '-' : '+', timezone_hour, timezone_min,
local_timezone);
return;
case kDateAndTime:
// TODO(842085): str may be silently truncated.
SNPrintF(str, "%s %s %02d %04d %02d:%02d:%02d GMT%c%02d%02d (%s)",
kShortWeekDays[weekday], kShortMonths[month], day, year, hour,
min, sec, (timezone_offset < 0) ? '-' : '+', timezone_hour,
......
......@@ -358,17 +358,17 @@ ICUTimezoneCache::~ICUTimezoneCache() { Clear(); }
const char* ICUTimezoneCache::LocalTimezone(double time_ms) {
bool is_dst = DaylightSavingsOffset(time_ms) != 0;
char* name = is_dst ? dst_timezone_name_ : timezone_name_;
if (name[0] == '\0') {
std::string* name = is_dst ? &dst_timezone_name_ : &timezone_name_;
if (name->empty()) {
icu::UnicodeString result;
GetTimeZone()->getDisplayName(is_dst, icu::TimeZone::LONG, result);
result += '\0';
icu::CheckedArrayByteSink byte_sink(name, kMaxTimezoneChars);
icu::StringByteSink<std::string> byte_sink(name);
result.toUTF8(byte_sink);
CHECK(!byte_sink.Overflowed());
}
return const_cast<const char*>(name);
DCHECK(!name->empty());
return name->c_str();
}
icu::TimeZone* ICUTimezoneCache::GetTimeZone() {
......@@ -418,8 +418,8 @@ double ICUTimezoneCache::LocalTimeOffset(double time_ms, bool is_utc) {
void ICUTimezoneCache::Clear() {
delete timezone_;
timezone_ = nullptr;
timezone_name_[0] = '\0';
dst_timezone_name_[0] = '\0';
timezone_name_.clear();
dst_timezone_name_.clear();
}
} // namespace internal
......
......@@ -9,6 +9,8 @@
#ifndef V8_INTL_H_
#define V8_INTL_H_
#include <string>
#include "src/base/timezone-cache.h"
#include "src/objects.h"
#include "src/objects/string.h"
......@@ -64,9 +66,8 @@ class ICUTimezoneCache : public base::TimezoneCache {
icu::TimeZone* timezone_;
static const int32_t kMaxTimezoneChars = 100;
char timezone_name_[kMaxTimezoneChars];
char dst_timezone_name_[kMaxTimezoneChars];
std::string timezone_name_;
std::string dst_timezone_name_;
};
} // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment