Commit 7ba3d732 authored by Chris Palmer's avatar Chris Palmer Committed by Commit Bot

Use checked arithmetic for Blink's StringImpl ref counting.

Bug: None
Change-Id: I7868559255a04fdf354fdd843c91ea0779a33072
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1603214Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Chris Palmer <palmer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659300}
parent eaaaa0a7
......@@ -86,10 +86,10 @@ class WTF_EXPORT StringImpl {
void* operator new(size_t, void* ptr) { return ptr; }
void operator delete(void*);
// Used to construct static strings, which have an special refCount that can
// never hit zero. This means that the static string will never be
// destroyed, which is important because static strings will be shared
// across threads & ref-counted in a non-threadsafe manner.
// Used to construct static strings, which have a special ref_count_ that can
// never hit zero. This means that the static string will never be destroyed,
// which is important because static strings will be shared across threads &
// ref-counted in a non-threadsafe manner.
enum ConstructEmptyStringTag { kConstructEmptyString };
explicit StringImpl(ConstructEmptyStringTag)
: ref_count_(1),
......@@ -279,7 +279,8 @@ class WTF_EXPORT StringImpl {
#if DCHECK_IS_ON()
DCHECK(IsStatic() || verifier_.OnRef(ref_count_)) << AsciiForDebugging();
#endif
++ref_count_;
if (!IsStatic())
ref_count_ = base::CheckAdd(ref_count_, 1).ValueOrDie();
}
ALWAYS_INLINE void Release() const {
......@@ -287,7 +288,9 @@ class WTF_EXPORT StringImpl {
DCHECK(IsStatic() || verifier_.OnDeref(ref_count_))
<< AsciiForDebugging() << " " << CurrentThread();
#endif
if (!--ref_count_)
if (!IsStatic())
ref_count_ = base::CheckSub(ref_count_, 1).ValueOrDie();
if (ref_count_ == 0)
DestroyIfNotStatic();
}
......
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