Commit 93e7d07e authored by Justin Schuh's avatar Justin Schuh Committed by Commit Bot

Warn on ignored return value from CheckedNumeric::AssignIfValid()

Adds a compiler warning that works in all compilation modes on
Clang/GCC, and in Prefast on MSVC. The rationale is all other
value-extracting CheckedNumeric<> functions already prevent the
caller from ignoring the validity state, but without this change
calling AssignIfValid() could silently ignore an invalid state.

Change-Id: I7e16f3cf7f026151ef39215bfe01c05e7c58b32f
Reviewed-on: https://chromium-review.googlesource.com/580296Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: Justin Schuh <jschuh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488707}
parent 20b379ba
......@@ -61,7 +61,13 @@ class CheckedNumeric {
// and is within the range supported by the destination type. Returns true if
// successful and false otherwise.
template <typename Dst>
constexpr bool AssignIfValid(Dst* result) const {
#if defined(__clang__) || defined(__GNUC__)
__attribute__((warn_unused_result))
#elif defined(_MSC_VER)
_Check_return_
#endif
constexpr bool
AssignIfValid(Dst* result) const {
return IsValid<Dst>() ? ((*result = static_cast<Dst>(state_.value())), true)
: false;
}
......
......@@ -330,8 +330,7 @@ void DatabaseImpl::Put(
}
UMA_HISTOGRAM_COUNTS_1000("WebCore.IndexedDB.PutBlobsCount",
blob_info.size());
uint64_t blob_size = 0;
total_blob_size.AssignIfValid(&blob_size);
uint64_t blob_size = total_blob_size.ValueOrDefault(0U);
if (blob_size != 0) {
// 1KB to 1GB.
UMA_HISTOGRAM_COUNTS_1M("WebCore.IndexedDB.PutBlobsTotalSize",
......
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