Commit 975cce11 authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

NOTREACHED on unexpected ScopedHString::Create() failure

Normally ScopedHString::Create() should only fail on out-of-memory
errors, which is already handled.

For other errors, currently we use DLOG which will silently pass nullptr
or empty string to downstream code, which may cause other errors which
will be hard to track.

This CL use NOTREACHED() for those errors so we'll get crashes in some
builds if it happens.

Change-Id: Ia7d556d1f981e106fe791c704727f7dd95477c5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119654
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753374}
parent 213d831e
......@@ -97,12 +97,16 @@ ScopedHString ScopedHString::Create(WStringPiece str) {
str.data(), checked_cast<UINT32>(str.length()), &hstr);
if (SUCCEEDED(hr))
return ScopedHString(hstr);
if (hr == E_OUTOFMEMORY) {
// This size is an approximation. The actual size likely includes
// sizeof(HSTRING_HEADER) as well.
base::TerminateBecauseOutOfMemory((str.length() + 1) * sizeof(wchar_t));
}
DLOG(ERROR) << "Failed to create HSTRING" << std::hex << hr;
// This should not happen at runtime. Otherwise we could silently pass nullptr
// or an empty string to downstream code.
NOTREACHED() << "Failed to create HSTRING: " << std::hex << hr;
return ScopedHString(nullptr);
}
......
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