0

Refactor base/safe_numerics.h

* Move into base/numerics subdirectory.
* Rename files for clarity.
* Add owners.
* Rename checked_numeric_cast to checked_cast.
* Fixup callsites and include paths.

BUG=332611
R=brettw@chromium.org, jam@chromium.org

Review URL: https://codereview.chromium.org/141113003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245418 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
jschuh@chromium.org
2014-01-17 03:32:40 +00:00
parent 8c00ed7b6f
commit cb15406554
53 changed files with 129 additions and 129 deletions
base
chrome
cloud_print/gcp20/prototype
components
plugins
policy
core
content
gpu/command_buffer/common
media/base
net/websockets
ppapi/host
printing
tools/imagediff
ui
win8/metro_driver

@@ -574,7 +574,7 @@
'process/process_util_unittest.cc', 'process/process_util_unittest.cc',
'profiler/tracked_time_unittest.cc', 'profiler/tracked_time_unittest.cc',
'rand_util_unittest.cc', 'rand_util_unittest.cc',
'safe_numerics_unittest.cc', 'numerics/safe_numerics_unittest.cc',
'scoped_clear_errno_unittest.cc', 'scoped_clear_errno_unittest.cc',
'scoped_native_library_unittest.cc', 'scoped_native_library_unittest.cc',
'scoped_observer.h', 'scoped_observer.h',

@@ -488,8 +488,8 @@
'rand_util_win.cc', 'rand_util_win.cc',
'run_loop.cc', 'run_loop.cc',
'run_loop.h', 'run_loop.h',
'safe_numerics.h', 'numerics/safe_conversions.h',
'safe_numerics_impl.h', 'numerics/safe_conversions_impl.h',
'safe_strerror_posix.cc', 'safe_strerror_posix.cc',
'safe_strerror_posix.h', 'safe_strerror_posix.h',
'scoped_native_library.cc', 'scoped_native_library.cc',

@@ -40,7 +40,7 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "third_party/icu/source/common/unicode/utf8.h" #include "third_party/icu/source/common/unicode/utf8.h"
@@ -319,7 +319,7 @@ uint8 MakeState(const StringSet& set,
State(new_state_initializer, State(new_state_initializer,
new_state_initializer + arraysize(new_state_initializer))); new_state_initializer + arraysize(new_state_initializer)));
const uint8 new_state_number = const uint8 new_state_number =
base::checked_numeric_cast<uint8>(states->size() - 1); base::checked_cast<uint8>(states->size() - 1);
CHECK(state_map->insert(std::make_pair(set, new_state_number)).second); CHECK(state_map->insert(std::make_pair(set, new_state_number)).second);
return new_state_number; return new_state_number;
} }

@@ -7,8 +7,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_base.h" #include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_snapshot_manager.h" #include "base/metrics/histogram_snapshot_manager.h"
#include "base/numerics/safe_conversions.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "base/safe_numerics.h"
#include "base/values.h" #include "base/values.h"
namespace base { namespace base {
@@ -75,7 +75,7 @@ void HistogramDeltaSerialization::DeserializeAndAddSamples(
const std::vector<std::string>& serialized_deltas) { const std::vector<std::string>& serialized_deltas) {
for (std::vector<std::string>::const_iterator it = serialized_deltas.begin(); for (std::vector<std::string>::const_iterator it = serialized_deltas.begin();
it != serialized_deltas.end(); ++it) { it != serialized_deltas.end(); ++it) {
Pickle pickle(it->data(), checked_numeric_cast<int>(it->size())); Pickle pickle(it->data(), checked_cast<int>(it->size()));
PickleIterator iter(pickle); PickleIterator iter(pickle);
DeserializeHistogramAndAddSamples(&iter); DeserializeHistogramAndAddSamples(&iter);
} }

3
base/numerics/OWNERS Normal file

@@ -0,0 +1,3 @@
jschuh@chromium.org
tsepez@chromium.org

@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef BASE_SAFE_NUMERICS_H_ #ifndef BASE_SAFE_CONVERSIONS_H_
#define BASE_SAFE_NUMERICS_H_ #define BASE_SAFE_CONVERSIONS_H_
#include <limits> #include <limits>
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics_impl.h" #include "base/numerics/safe_conversions_impl.h"
namespace base { namespace base {
@@ -19,11 +19,11 @@ inline bool IsValueInRangeForNumericType(Src value) {
return internal::RangeCheck<Dst>(value) == internal::TYPE_VALID; return internal::RangeCheck<Dst>(value) == internal::TYPE_VALID;
} }
// checked_numeric_cast<> is analogous to static_cast<> for numeric types, // checked_cast<> is analogous to static_cast<> for numeric types,
// except that it CHECKs that the specified numeric conversion will not // except that it CHECKs that the specified numeric conversion will not
// overflow or underflow. NaN source will always trigger a CHECK. // overflow or underflow. NaN source will always trigger a CHECK.
template <typename Dst, typename Src> template <typename Dst, typename Src>
inline Dst checked_numeric_cast(Src value) { inline Dst checked_cast(Src value) {
CHECK(IsValueInRangeForNumericType<Dst>(value)); CHECK(IsValueInRangeForNumericType<Dst>(value));
return static_cast<Dst>(value); return static_cast<Dst>(value);
} }
@@ -59,4 +59,5 @@ inline Dst saturated_cast(Src value) {
} // namespace base } // namespace base
#endif // BASE_SAFE_NUMERICS_H_ #endif // BASE_SAFE_CONVERSIONS_H_

@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef BASE_SAFE_NUMERICS_IMPL_H_ #ifndef BASE_SAFE_CONVERSIONS_IMPL_H_
#define BASE_SAFE_NUMERICS_IMPL_H_ #define BASE_SAFE_CONVERSIONS_IMPL_H_
#include <limits> #include <limits>
@@ -179,5 +179,5 @@ inline RangeCheckResult RangeCheck(Src value) {
} // namespace internal } // namespace internal
} // namespace base } // namespace base
#endif // BASE_SAFE_NUMERICS_IMPL_H_ #endif // BASE_SAFE_CONVERSIONS_IMPL_H_

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include <stdint.h> #include <stdint.h>
@@ -258,7 +258,7 @@ TEST(SafeNumerics, CastTests) {
double double_infinity = std::numeric_limits<float>::infinity(); double double_infinity = std::numeric_limits<float>::infinity();
// Just test that the cast compiles, since the other tests cover logic. // Just test that the cast compiles, since the other tests cover logic.
EXPECT_EQ(0, base::checked_numeric_cast<int>(static_cast<size_t>(0))); EXPECT_EQ(0, base::checked_cast<int>(static_cast<size_t>(0)));
// Test various saturation corner cases. // Test various saturation corner cases.
EXPECT_EQ(saturated_cast<int>(small_negative), EXPECT_EQ(saturated_cast<int>(small_negative),
@@ -277,3 +277,4 @@ TEST(SafeNumerics, CastTests) {
} // namespace internal } // namespace internal
} // namespace base } // namespace base

@@ -6,8 +6,8 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/safe_numerics.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
@@ -62,7 +62,7 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest {
int64 file_size; int64 file_size;
ASSERT_TRUE(base::GetFileSize(GetCommonDataDir().AppendASCII("test.jpg"), ASSERT_TRUE(base::GetFileSize(GetCommonDataDir().AppendASCII("test.jpg"),
&file_size)); &file_size));
test_jpg_size_ = base::checked_numeric_cast<int>(file_size); test_jpg_size_ = base::checked_cast<int>(file_size);
} }
virtual void TearDownOnMainThread() OVERRIDE { virtual void TearDownOnMainThread() OVERRIDE {

@@ -15,8 +15,8 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/json/json_file_value_serializer.h" #include "base/json/json_file_value_serializer.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/safe_numerics.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
@@ -173,7 +173,7 @@ scoped_refptr<Extension> ConvertWebAppToExtension(
} }
const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]);
int size = base::checked_numeric_cast<int>(image_data.size()); int size = base::checked_cast<int>(image_data.size());
if (file_util::WriteFile(icon_file, image_data_ptr, size) != size) { if (file_util::WriteFile(icon_file, image_data_ptr, size) != size) {
LOG(ERROR) << "Could not write icon file."; LOG(ERROR) << "Could not write icon file.";
return NULL; return NULL;

@@ -15,8 +15,8 @@
#include "base/memory/scoped_handle.h" #include "base/memory/scoped_handle.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/safe_numerics.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
@@ -628,7 +628,7 @@ base::DictionaryValue* SandboxedUnpacker::RewriteManifestFile(
base::FilePath manifest_path = base::FilePath manifest_path =
extension_root_.Append(kManifestFilename); extension_root_.Append(kManifestFilename);
int size = base::checked_numeric_cast<int>(manifest_json.size()); int size = base::checked_cast<int>(manifest_json.size());
if (file_util::WriteFile(manifest_path, manifest_json.data(), size) != size) { if (file_util::WriteFile(manifest_path, manifest_json.data(), size) != size) {
// Error saving manifest.json. // Error saving manifest.json.
ReportFailure( ReportFailure(
@@ -741,7 +741,7 @@ bool SandboxedUnpacker::RewriteImageFiles(SkBitmap* install_icon) {
// Note: we're overwriting existing files that the utility process wrote, // Note: we're overwriting existing files that the utility process wrote,
// so we can be sure the directory exists. // so we can be sure the directory exists.
const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]);
int size = base::checked_numeric_cast<int>(image_data.size()); int size = base::checked_cast<int>(image_data.size());
if (file_util::WriteFile(path, image_data_ptr, size) != size) { if (file_util::WriteFile(path, image_data_ptr, size) != size) {
// Error saving theme image. // Error saving theme image.
ReportFailure( ReportFailure(
@@ -810,7 +810,7 @@ bool SandboxedUnpacker::RewriteCatalogFiles() {
// Note: we're overwriting existing files that the utility process read, // Note: we're overwriting existing files that the utility process read,
// so we can be sure the directory exists. // so we can be sure the directory exists.
int size = base::checked_numeric_cast<int>(catalog_json.size()); int size = base::checked_cast<int>(catalog_json.size());
if (file_util::WriteFile(path, catalog_json.c_str(), size) != size) { if (file_util::WriteFile(path, catalog_json.c_str(), size) != size) {
// Error saving catalog. // Error saving catalog.
ReportFailure( ReportFailure(

@@ -6,7 +6,7 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/test/values_test_util.h" #include "base/test/values_test_util.h"
#include "chrome/browser/extensions/extension_creator.h" #include "chrome/browser/extensions/extension_creator.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
@@ -31,7 +31,7 @@ void TestExtensionDir::WriteManifest(base::StringPiece manifest) {
void TestExtensionDir::WriteFile(const base::FilePath::StringType& filename, void TestExtensionDir::WriteFile(const base::FilePath::StringType& filename,
base::StringPiece contents) { base::StringPiece contents) {
EXPECT_EQ( EXPECT_EQ(
base::checked_numeric_cast<int>(contents.size()), base::checked_cast<int>(contents.size()),
file_util::WriteFile( file_util::WriteFile(
dir_.path().Append(filename), contents.data(), contents.size())); dir_.path().Append(filename), contents.data(), contents.size()));
} }

@@ -7,7 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "chrome/browser/media_galleries/linux/snapshot_file_details.h" #include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
#include "chrome/browser/storage_monitor/storage_monitor.h" #include "chrome/browser/storage_monitor/storage_monitor.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
@@ -28,9 +28,9 @@ uint32 WriteDataChunkIntoSnapshotFileOnFileThread(
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
int bytes_written = int bytes_written =
file_util::AppendToFile(snapshot_file_path, data.data(), file_util::AppendToFile(snapshot_file_path, data.data(),
base::checked_numeric_cast<int>(data.size())); base::checked_cast<int>(data.size()));
return (static_cast<int>(data.size()) == bytes_written) ? return (static_cast<int>(data.size()) == bytes_written) ?
base::checked_numeric_cast<uint32>(bytes_written) : 0; base::checked_cast<uint32>(bytes_written) : 0;
} }
} // namespace } // namespace

@@ -4,7 +4,7 @@
#include "chrome/browser/media_galleries/linux/snapshot_file_details.h" #include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// SnapshotRequestInfo // // SnapshotRequestInfo //
@@ -64,5 +64,5 @@ uint32 SnapshotFileDetails::BytesToRead() const {
static const uint32 kReadChunkSize = 1024 * 1024; static const uint32 kReadChunkSize = 1024 * 1024;
return std::min( return std::min(
kReadChunkSize, kReadChunkSize,
base::checked_numeric_cast<uint32>(file_info_.size) - bytes_written_); base::checked_cast<uint32>(file_info_.size) - bytes_written_);
} }

@@ -12,7 +12,7 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/time/time.h" #include "base/time/time.h"
@@ -385,9 +385,9 @@ DWORD CopyDataChunkToLocalFile(IStream* stream,
DCHECK_GT(bytes_read, 0U); DCHECK_GT(bytes_read, 0U);
CHECK_LE(bytes_read, buffer.length()); CHECK_LE(bytes_read, buffer.length());
int data_len = int data_len =
base::checked_numeric_cast<int>( base::checked_cast<int>(
std::min(bytes_read, std::min(bytes_read,
base::checked_numeric_cast<DWORD>(buffer.length()))); base::checked_cast<DWORD>(buffer.length())));
if (file_util::AppendToFile(local_path, buffer.c_str(), data_len) != data_len) if (file_util::AppendToFile(local_path, buffer.c_str(), data_len) != data_len)
return 0U; return 0U;
return data_len; return data_len;

@@ -6,9 +6,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/safe_numerics.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/component_updater/component_updater_service.h" #include "chrome/browser/component_updater/component_updater_service.h"
@@ -168,7 +168,7 @@ bool CRLSetFetcher::Install(const base::DictionaryValue& manifest,
LOG(WARNING) << "Failed to parse CRL set from update CRX"; LOG(WARNING) << "Failed to parse CRL set from update CRX";
return false; return false;
} }
int size = base::checked_numeric_cast<int>(crl_set_bytes.size()); int size = base::checked_cast<int>(crl_set_bytes.size());
if (file_util::WriteFile(save_to, crl_set_bytes.data(), size) != size) { if (file_util::WriteFile(save_to, crl_set_bytes.data(), size) != size) {
LOG(WARNING) << "Failed to save new CRL set to disk"; LOG(WARNING) << "Failed to save new CRL set to disk";
// We don't return false here because we can still use this CRL set. When // We don't return false here because we can still use this CRL set. When
@@ -184,7 +184,7 @@ bool CRLSetFetcher::Install(const base::DictionaryValue& manifest,
VLOG(1) << "Applied CRL set delta #" << crl_set_->sequence() VLOG(1) << "Applied CRL set delta #" << crl_set_->sequence()
<< "->#" << new_crl_set->sequence(); << "->#" << new_crl_set->sequence();
const std::string new_crl_set_bytes = new_crl_set->Serialize(); const std::string new_crl_set_bytes = new_crl_set->Serialize();
int size = base::checked_numeric_cast<int>(new_crl_set_bytes.size()); int size = base::checked_cast<int>(new_crl_set_bytes.size());
if (file_util::WriteFile(save_to, new_crl_set_bytes.data(), size) != size) { if (file_util::WriteFile(save_to, new_crl_set_bytes.data(), size) != size) {
LOG(WARNING) << "Failed to save new CRL set to disk"; LOG(WARNING) << "Failed to save new CRL set to disk";
// We don't return false here because we can still use this CRL set. When // We don't return false here because we can still use this CRL set. When

@@ -6,10 +6,10 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/numerics/safe_conversions.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h" #include "base/prefs/scoped_user_pref_update.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/safe_numerics.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/time/time.h" #include "base/time/time.h"
@@ -65,10 +65,10 @@ size_t GetGroupIndex(size_t domain_index, PrefService* pref_service) {
pref_service, prefs::kPasswordManagerGroupsForDomains); pref_service, prefs::kPasswordManagerGroupsForDomains);
// This value has not been generated yet. // This value has not been generated yet.
result = result =
base::checked_numeric_cast<int>(base::RandGenerator(kGroupsPerDomain)); base::checked_cast<int>(base::RandGenerator(kGroupsPerDomain));
group_indices_updater->Set(domain_index, new FundamentalValue(result)); group_indices_updater->Set(domain_index, new FundamentalValue(result));
} }
return base::checked_numeric_cast<size_t>(result); return base::checked_cast<size_t>(result);
} }
} // namespace } // namespace

@@ -17,7 +17,6 @@
#include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/safe_numerics.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"

@@ -11,7 +11,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"

@@ -15,9 +15,9 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process/launch.h" #include "base/process/launch.h"
#include "base/safe_numerics.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
@@ -351,7 +351,7 @@ bool CreateVisualElementsManifest(const base::FilePath& src_path,
// Write the manifest to |src_path|. // Write the manifest to |src_path|.
const std::string manifest(UTF16ToUTF8(manifest16)); const std::string manifest(UTF16ToUTF8(manifest16));
int size = base::checked_numeric_cast<int>(manifest.size()); int size = base::checked_cast<int>(manifest.size());
if (file_util::WriteFile( if (file_util::WriteFile(
src_path.Append(installer::kVisualElementsManifest), src_path.Append(installer::kVisualElementsManifest),
manifest.c_str(), size) == size) { manifest.c_str(), size) == size) {

@@ -6,7 +6,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
@@ -26,13 +26,13 @@
#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/resource_tracker.h"
#include "ppapi/shared_impl/var.h" #include "ppapi/shared_impl/var.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h" #include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebPluginContainer.h" #include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "third_party/WebKit/public/web/WebView.h" #include "third_party/WebKit/public/web/WebView.h"
#include "third_party/icu/source/i18n/unicode/usearch.h" #include "third_party/icu/source/i18n/unicode/usearch.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
@@ -58,7 +58,7 @@ class PrivateFontFile : public ppapi::Resource {
size_t temp_size = static_cast<size_t>(*output_length); size_t temp_size = static_cast<size_t>(*output_length);
bool rv = content::GetFontTable( bool rv = content::GetFontTable(
fd_, table, 0 /* offset */, static_cast<uint8_t*>(output), &temp_size); fd_, table, 0 /* offset */, static_cast<uint8_t*>(output), &temp_size);
*output_length = base::checked_numeric_cast<uint32_t>(temp_size); *output_length = base::checked_cast<uint32_t>(temp_size);
return rv; return rv;
} }

@@ -12,7 +12,7 @@
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/json/json_file_value_serializer.h" #include "base/json/json_file_value_serializer.h"
#include "base/memory/scoped_handle.h" #include "base/memory/scoped_handle.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
@@ -86,7 +86,7 @@ bool PathContainsParentDirectory(const base::FilePath& path) {
} }
bool WritePickle(const IPC::Message& pickle, const base::FilePath& dest_path) { bool WritePickle(const IPC::Message& pickle, const base::FilePath& dest_path) {
int size = base::checked_numeric_cast<int>(pickle.size()); int size = base::checked_cast<int>(pickle.size());
const char* data = static_cast<const char*>(pickle.data()); const char* data = static_cast<const char*>(pickle.data());
int bytes_written = file_util::WriteFile(dest_path, data, size); int bytes_written = file_util::WriteFile(dest_path, data, size);
return (bytes_written == size); return (bytes_written == size);

@@ -8,7 +8,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/values.h" #include "base/values.h"
namespace { namespace {
@@ -74,7 +74,7 @@ bool SaveToFile(const base::FilePath& path, const PrinterState& state) {
base::JSONWriter::WriteWithOptions(&json, base::JSONWriter::WriteWithOptions(&json,
base::JSONWriter::OPTIONS_PRETTY_PRINT, base::JSONWriter::OPTIONS_PRETTY_PRINT,
&json_str); &json_str);
int size = base::checked_numeric_cast<int>(json_str.size()); int size = base::checked_cast<int>(json_str.size());
return (file_util::WriteFile(path, json_str.data(), size) == size); return (file_util::WriteFile(path, json_str.data(), size) == size);
} }

@@ -6,7 +6,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "content/public/renderer/web_preferences.h" #include "content/public/renderer/web_preferences.h"
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/WebSize.h" #include "third_party/WebKit/public/platform/WebSize.h"
@@ -74,15 +74,15 @@ void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) {
for (std::list<std::string>::iterator it = data_.begin(); it != data_.end(); for (std::list<std::string>::iterator it = data_.begin(); it != data_.end();
++it) { ++it) {
plugin->didReceiveData( plugin->didReceiveData(
it->c_str(), base::checked_numeric_cast<int, size_t>(it->length())); it->c_str(), base::checked_cast<int, size_t>(it->length()));
total_bytes += it->length(); total_bytes += it->length();
} }
UMA_HISTOGRAM_MEMORY_KB( UMA_HISTOGRAM_MEMORY_KB(
"PluginDocument.Memory", "PluginDocument.Memory",
(base::checked_numeric_cast<int, size_t>(total_bytes / 1024))); (base::checked_cast<int, size_t>(total_bytes / 1024)));
UMA_HISTOGRAM_COUNTS( UMA_HISTOGRAM_COUNTS(
"PluginDocument.NumChunks", "PluginDocument.NumChunks",
(base::checked_numeric_cast<int, size_t>(data_.size()))); (base::checked_cast<int, size_t>(data_.size())));
} }
if (finished_loading_) { if (finished_loading_) {
plugin->didFinishLoading(); plugin->didFinishLoading();

@@ -9,7 +9,7 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
@@ -82,7 +82,7 @@ bool ResourceCache::Store(const std::string& key,
// between these two calls. There is nothing in file_util that could be used // between these two calls. There is nothing in file_util that could be used
// to protect against such races, especially as the cache is cross-platform // to protect against such races, especially as the cache is cross-platform
// and therefore cannot use any POSIX-only tricks. // and therefore cannot use any POSIX-only tricks.
int size = base::checked_numeric_cast<int>(data.size()); int size = base::checked_cast<int>(data.size());
return VerifyKeyPathAndGetSubkeyPath(key, true, subkey, &subkey_path) && return VerifyKeyPathAndGetSubkeyPath(key, true, subkey, &subkey_path) &&
base::DeleteFile(subkey_path, false) && base::DeleteFile(subkey_path, false) &&
(file_util::WriteFile(subkey_path, data.data(), size) == size); (file_util::WriteFile(subkey_path, data.data(), size) == size);

@@ -9,8 +9,8 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/safe_numerics.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "content/public/test/test_file_system_context.h" #include "content/public/test/test_file_system_context.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
@@ -287,7 +287,7 @@ class BlobURLRequestJobTest : public testing::Test {
const std::vector<BlobData::Item>& items = blob_data_->items(); const std::vector<BlobData::Item>& items = blob_data_->items();
for (std::vector<BlobData::Item>::const_iterator it = items.begin(); for (std::vector<BlobData::Item>::const_iterator it = items.begin();
it != items.end(); ++it) { it != items.end(); ++it) {
int64 length = base::checked_numeric_cast<int64>(it->length()); int64 length = base::checked_cast<int64>(it->length());
CHECK(length <= kint64max - total); CHECK(length <= kint64max - total);
total += length; total += length;
} }

@@ -6,7 +6,7 @@
#include <algorithm> #include <algorithm>
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "content/browser/renderer_host/pepper/pepper_truetype_font_list.h" #include "content/browser/renderer_host/pepper/pepper_truetype_font_list.h"
#include "content/common/font_list.h" #include "content/common/font_list.h"
@@ -84,7 +84,7 @@ int32_t FontMessageFilter::OnHostMsgGetFontFamilies(
context->reply_msg = context->reply_msg =
PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply(font_families); PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply(font_families);
return base::checked_numeric_cast<int32_t>(font_families.size()); return base::checked_cast<int32_t>(font_families.size());
} }
int32_t FontMessageFilter::OnHostMsgGetFontsInFamily( int32_t FontMessageFilter::OnHostMsgGetFontsInFamily(
@@ -97,7 +97,7 @@ int32_t FontMessageFilter::OnHostMsgGetFontsInFamily(
context->reply_msg = context->reply_msg =
PpapiPluginMsg_TrueTypeFontSingleton_GetFontsInFamilyReply( PpapiPluginMsg_TrueTypeFontSingleton_GetFontsInFamilyReply(
fonts_in_family); fonts_in_family);
return base::checked_numeric_cast<int32_t>(fonts_in_family.size()); return base::checked_cast<int32_t>(fonts_in_family.size());
} }
} // namespace } // namespace

@@ -6,7 +6,7 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
#include "content/browser/speech/audio_buffer.h" #include "content/browser/speech/audio_buffer.h"
@@ -20,7 +20,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using base::HostToNet32; using base::HostToNet32;
using base::checked_numeric_cast; using base::checked_cast;
using net::URLRequestStatus; using net::URLRequestStatus;
using net::TestURLFetcher; using net::TestURLFetcher;
using net::TestURLFetcherFactory; using net::TestURLFetcherFactory;
@@ -490,7 +490,7 @@ std::string GoogleStreamingRemoteEngineTest::SerializeProtobufResponse(
// Prepend 4 byte prefix length indication to the protobuf message as // Prepend 4 byte prefix length indication to the protobuf message as
// envisaged by the google streaming recognition webservice protocol. // envisaged by the google streaming recognition webservice protocol.
uint32 prefix = HostToNet32(checked_numeric_cast<uint32>(msg_string.size())); uint32 prefix = HostToNet32(checked_cast<uint32>(msg_string.size()));
msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix));
return msg_string; return msg_string;

@@ -6,7 +6,7 @@
#include <algorithm> #include <algorithm>
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
#include "content/port/browser/vibration_provider.h" #include "content/port/browser/vibration_provider.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
@@ -48,7 +48,7 @@ void VibrationMessageFilter::OnVibrate(int64 milliseconds) {
// Though the Blink implementation already sanitizes vibration times, don't // Though the Blink implementation already sanitizes vibration times, don't
// trust any values passed from the renderer. // trust any values passed from the renderer.
milliseconds = std::max(kMinimumVibrationDurationMs, std::min(milliseconds, milliseconds = std::max(kMinimumVibrationDurationMs, std::min(milliseconds,
base::checked_numeric_cast<int64>(blink::kVibrationDurationMax))); base::checked_cast<int64>(blink::kVibrationDurationMax)));
provider_->Vibrate(milliseconds); provider_->Vibrate(milliseconds);
} }

@@ -6,7 +6,6 @@
#include <algorithm> #include <algorithm>
#include "base/safe_numerics.h"
#include "content/browser/vibration/vibration_message_filter.h" #include "content/browser/vibration/vibration_message_filter.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
#include "jni/VibrationProvider_jni.h" #include "jni/VibrationProvider_jni.h"

@@ -8,10 +8,10 @@
#include "base/debug/trace_event.h" #include "base/debug/trace_event.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/posix/unix_domain_socket_linux.h" #include "base/posix/unix_domain_socket_linux.h"
#include "base/safe_numerics.h"
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
#include "content/common/sandbox_linux/sandbox_linux.h" #include "content/common/sandbox_linux/sandbox_linux.h"
#include "third_party/WebKit/public/platform/linux/WebFontFamily.h" #include "third_party/WebKit/public/platform/linux/WebFontFamily.h"
@@ -117,7 +117,7 @@ bool GetFontTable(int fd, uint32_t table_tag, off_t offset,
struct stat st; struct stat st;
if (fstat(fd, &st) < 0) if (fstat(fd, &st) < 0)
return false; return false;
data_length = base::checked_numeric_cast<size_t>(st.st_size); data_length = base::checked_cast<size_t>(st.st_size);
} else { } else {
// Get a font table. Read the header to find its offset in the file. // Get a font table. Read the header to find its offset in the file.
uint16_t num_tables; uint16_t num_tables;
@@ -134,7 +134,7 @@ bool GetFontTable(int fd, uint32_t table_tag, off_t offset,
scoped_ptr<uint8_t[]> table_entries(new uint8_t[directory_size]); scoped_ptr<uint8_t[]> table_entries(new uint8_t[directory_size]);
n = HANDLE_EINTR(pread(fd, table_entries.get(), directory_size, n = HANDLE_EINTR(pread(fd, table_entries.get(), directory_size,
12 /* skip the SFNT header */)); 12 /* skip the SFNT header */));
if (n != base::checked_numeric_cast<ssize_t>(directory_size)) if (n != base::checked_cast<ssize_t>(directory_size))
return false; return false;
for (uint16_t i = 0; i < num_tables; ++i) { for (uint16_t i = 0; i < num_tables; ++i) {
@@ -155,7 +155,7 @@ bool GetFontTable(int fd, uint32_t table_tag, off_t offset,
return false; return false;
// Clamp |offset| inside the allowable range. This allows the read to succeed // Clamp |offset| inside the allowable range. This allows the read to succeed
// but return 0 bytes. // but return 0 bytes.
offset = std::min(offset, base::checked_numeric_cast<off_t>(data_length)); offset = std::min(offset, base::checked_cast<off_t>(data_length));
// Make sure it's safe to add the data offset and the caller's logical offset. // Make sure it's safe to add the data offset and the caller's logical offset.
// Define the maximum positive offset on 32 bit systems. // Define the maximum positive offset on 32 bit systems.
static const off_t kMaxPositiveOffset32 = 0x7FFFFFFF; // 2 GB - 1. static const off_t kMaxPositiveOffset32 = 0x7FFFFFFF; // 2 GB - 1.
@@ -169,7 +169,7 @@ bool GetFontTable(int fd, uint32_t table_tag, off_t offset,
// 'output_length' holds the maximum amount of data the caller can accept. // 'output_length' holds the maximum amount of data the caller can accept.
data_length = std::min(data_length, *output_length); data_length = std::min(data_length, *output_length);
ssize_t n = HANDLE_EINTR(pread(fd, output, data_length, data_offset)); ssize_t n = HANDLE_EINTR(pread(fd, output, data_length, data_offset));
if (n != base::checked_numeric_cast<ssize_t>(data_length)) if (n != base::checked_cast<ssize_t>(data_length))
return false; return false;
} }
*output_length = data_length; *output_length = data_length;

@@ -8,8 +8,8 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/files/memory_mapped_file.h" #include "base/files/memory_mapped_file.h"
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/numerics/safe_conversions.h"
#include "base/process/process.h" #include "base/process/process.h"
#include "base/safe_numerics.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "content/common/gpu/media/exynos_video_encode_accelerator.h" #include "content/common/gpu/media/exynos_video_encode_accelerator.h"
@@ -495,7 +495,7 @@ void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id,
seen_keyframe_in_this_buffer_ = false; seen_keyframe_in_this_buffer_ = false;
if (save_to_file_) { if (save_to_file_) {
int size = base::checked_numeric_cast<int>(payload_size); int size = base::checked_cast<int>(payload_size);
EXPECT_EQ(file_util::AppendToFile( EXPECT_EQ(file_util::AppendToFile(
base::FilePath::FromUTF8Unsafe(test_stream_.out_filename), base::FilePath::FromUTF8Unsafe(test_stream_.out_filename),
static_cast<char*>(shm->memory()), static_cast<char*>(shm->memory()),

@@ -9,7 +9,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "content/child/child_thread.h" #include "content/child/child_thread.h"
@@ -418,7 +418,7 @@ scoped_refptr<media::VideoFrame> RTCVideoDecoder::CreateVideoFrame(
DCHECK(decoder_texture_target_); DCHECK(decoder_texture_target_);
// Convert timestamp from 90KHz to ms. // Convert timestamp from 90KHz to ms.
base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue( base::TimeDelta timestamp_ms = base::TimeDelta::FromInternalValue(
base::checked_numeric_cast<uint64_t>(timestamp) * 1000 / 90); base::checked_cast<uint64_t>(timestamp) * 1000 / 90);
return media::VideoFrame::WrapNativeTexture( return media::VideoFrame::WrapNativeTexture(
make_scoped_ptr(new media::VideoFrame::MailboxHolder( make_scoped_ptr(new media::VideoFrame::MailboxHolder(
pb.texture_mailbox(), pb.texture_mailbox(),

@@ -7,7 +7,7 @@
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/debug/trace_event.h" #include "base/debug/trace_event.h"
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop_proxy.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "content/renderer/pepper/ppb_buffer_impl.h" #include "content/renderer/pepper/ppb_buffer_impl.h"
#include "media/base/audio_buffer.h" #include "media/base/audio_buffer.h"
#include "media/base/audio_decoder_config.h" #include "media/base/audio_decoder_config.h"
@@ -998,7 +998,7 @@ bool ContentDecryptorDelegate::DeserializeAudioFrames(
// We should *not* have empty frames in the list. // We should *not* have empty frames in the list.
if (frame_size <= 0 || if (frame_size <= 0 ||
bytes_left < base::checked_numeric_cast<size_t>(frame_size)) { bytes_left < base::checked_cast<size_t>(frame_size)) {
return false; return false;
} }

@@ -4,7 +4,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
#include "content/public/common/child_process_sandbox_support_linux.h" #include "content/public/common/child_process_sandbox_support_linux.h"
#include "content/renderer/pepper/pepper_truetype_font.h" #include "content/renderer/pepper/pepper_truetype_font.h"
@@ -144,7 +144,7 @@ int32_t PepperTrueTypeFontLinux::GetTable(uint32_t table_tag,
&table_size)) &table_size))
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
return base::checked_numeric_cast<int32_t>(table_size); return base::checked_cast<int32_t>(table_size);
} }
} // namespace } // namespace

@@ -5,7 +5,7 @@
#include "content/renderer/pepper/pepper_video_source_host.h" #include "content/renderer/pepper/pepper_video_source_host.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "content/public/renderer/renderer_ppapi_host.h" #include "content/public/renderer/renderer_ppapi_host.h"
#include "content/renderer/pepper/ppb_image_data_impl.h" #include "content/renderer/pepper/ppb_image_data_impl.h"
#include "content/renderer/render_thread_impl.h" #include "content/renderer/render_thread_impl.h"
@@ -134,8 +134,8 @@ void PepperVideoSourceHost::SendGetFrameReply() {
DCHECK(last_frame_.get()); DCHECK(last_frame_.get());
scoped_ptr<cricket::VideoFrame> frame(last_frame_.release()); scoped_ptr<cricket::VideoFrame> frame(last_frame_.release());
int32_t width = base::checked_numeric_cast<int32_t>(frame->GetWidth()); int32_t width = base::checked_cast<int32_t>(frame->GetWidth());
int32_t height = base::checked_numeric_cast<int32_t>(frame->GetHeight()); int32_t height = base::checked_cast<int32_t>(frame->GetHeight());
PP_ImageDataDesc image_desc; PP_ImageDataDesc image_desc;
IPC::PlatformFileForTransit image_handle; IPC::PlatformFileForTransit image_handle;
uint32_t byte_count; uint32_t byte_count;

@@ -10,8 +10,8 @@
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/numerics/safe_conversions.h"
#include "base/platform_file.h" #include "base/platform_file.h"
#include "base/safe_numerics.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/child/database_util.h" #include "content/child/database_util.h"
@@ -1057,7 +1057,7 @@ blink::WebCrypto* RendererWebKitPlatformSupportImpl::crypto() {
void RendererWebKitPlatformSupportImpl::vibrate(unsigned int milliseconds) { void RendererWebKitPlatformSupportImpl::vibrate(unsigned int milliseconds) {
RenderThread::Get()->Send( RenderThread::Get()->Send(
new ViewHostMsg_Vibrate(base::checked_numeric_cast<int64>(milliseconds))); new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds)));
} }
void RendererWebKitPlatformSupportImpl::cancelVibration() { void RendererWebKitPlatformSupportImpl::cancelVibration() {

@@ -5,7 +5,7 @@
#include "content/test/mock_google_streaming_server.h" #include "content/test/mock_google_streaming_server.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
@@ -18,7 +18,7 @@
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
using base::HostToNet32; using base::HostToNet32;
using base::checked_numeric_cast; using base::checked_cast;
namespace content { namespace content {
@@ -101,7 +101,7 @@ void MockGoogleStreamingServer::SimulateResult(
// Prepend 4 byte prefix length indication to the protobuf message as // Prepend 4 byte prefix length indication to the protobuf message as
// envisaged by the google streaming recognition webservice protocol. // envisaged by the google streaming recognition webservice protocol.
uint32 prefix = HostToNet32(checked_numeric_cast<uint32>(msg_string.size())); uint32 prefix = HostToNet32(checked_cast<uint32>(msg_string.size()));
msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix));
SimulateServerResponse(true, msg_string); SimulateServerResponse(true, msg_string);

@@ -12,7 +12,6 @@
#include <string.h> #include <string.h>
#include "base/safe_numerics.h"
#include "gpu/command_buffer/common/bitfield_helpers.h" #include "gpu/command_buffer/common/bitfield_helpers.h"
#include "gpu/command_buffer/common/cmd_buffer_common.h" #include "gpu/command_buffer/common/cmd_buffer_common.h"
#include "gpu/command_buffer/common/gles2_cmd_ids.h" #include "gpu/command_buffer/common/gles2_cmd_ids.h"

@@ -14,7 +14,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "jni/MediaCodecBridge_jni.h" #include "jni/MediaCodecBridge_jni.h"
@@ -225,7 +225,7 @@ MediaCodecStatus MediaCodecBridge::QueueInputBuffer(
size_t data_size, size_t data_size,
const base::TimeDelta& presentation_time) { const base::TimeDelta& presentation_time) {
DVLOG(3) << __PRETTY_FUNCTION__ << index << ": " << data_size; DVLOG(3) << __PRETTY_FUNCTION__ << index << ": " << data_size;
if (data_size > base::checked_numeric_cast<size_t>(kint32max)) if (data_size > base::checked_cast<size_t>(kint32max))
return MEDIA_CODEC_ERROR; return MEDIA_CODEC_ERROR;
if (data && !FillInputBuffer(index, data, data_size)) if (data && !FillInputBuffer(index, data, data_size))
return MEDIA_CODEC_ERROR; return MEDIA_CODEC_ERROR;
@@ -252,7 +252,7 @@ MediaCodecStatus MediaCodecBridge::QueueSecureInputBuffer(
int subsamples_size, int subsamples_size,
const base::TimeDelta& presentation_time) { const base::TimeDelta& presentation_time) {
DVLOG(3) << __PRETTY_FUNCTION__ << index << ": " << data_size; DVLOG(3) << __PRETTY_FUNCTION__ << index << ": " << data_size;
if (data_size > base::checked_numeric_cast<size_t>(kint32max)) if (data_size > base::checked_cast<size_t>(kint32max))
return MEDIA_CODEC_ERROR; return MEDIA_CODEC_ERROR;
if (data && !FillInputBuffer(index, data, data_size)) if (data && !FillInputBuffer(index, data, data_size))
return MEDIA_CODEC_ERROR; return MEDIA_CODEC_ERROR;
@@ -349,9 +349,9 @@ MediaCodecStatus MediaCodecBridge::DequeueOutputBuffer(
Java_MediaCodecBridge_dequeueOutputBuffer( Java_MediaCodecBridge_dequeueOutputBuffer(
env, j_media_codec_.obj(), timeout.InMicroseconds()); env, j_media_codec_.obj(), timeout.InMicroseconds());
*index = Java_DequeueOutputResult_index(env, result.obj()); *index = Java_DequeueOutputResult_index(env, result.obj());
*offset = base::checked_numeric_cast<size_t>( *offset = base::checked_cast<size_t>(
Java_DequeueOutputResult_offset(env, result.obj())); Java_DequeueOutputResult_offset(env, result.obj()));
*size = base::checked_numeric_cast<size_t>( *size = base::checked_cast<size_t>(
Java_DequeueOutputResult_numBytes(env, result.obj())); Java_DequeueOutputResult_numBytes(env, result.obj()));
if (presentation_time) { if (presentation_time) {
*presentation_time = base::TimeDelta::FromMicroseconds( *presentation_time = base::TimeDelta::FromMicroseconds(
@@ -408,7 +408,7 @@ void MediaCodecBridge::GetInputBuffer(int input_buffer_index,
ScopedJavaLocalRef<jobject> j_buffer(Java_MediaCodecBridge_getInputBuffer( ScopedJavaLocalRef<jobject> j_buffer(Java_MediaCodecBridge_getInputBuffer(
env, j_media_codec_.obj(), input_buffer_index)); env, j_media_codec_.obj(), input_buffer_index));
*data = static_cast<uint8*>(env->GetDirectBufferAddress(j_buffer.obj())); *data = static_cast<uint8*>(env->GetDirectBufferAddress(j_buffer.obj()));
*capacity = base::checked_numeric_cast<size_t>( *capacity = base::checked_cast<size_t>(
env->GetDirectBufferCapacity(j_buffer.obj())); env->GetDirectBufferCapacity(j_buffer.obj()));
} }
@@ -590,7 +590,7 @@ bool AudioCodecBridge::ConfigureMediaFormat(jobject j_format,
void AudioCodecBridge::PlayOutputBuffer(int index, size_t size) { void AudioCodecBridge::PlayOutputBuffer(int index, size_t size) {
DCHECK_LE(0, index); DCHECK_LE(0, index);
int numBytes = base::checked_numeric_cast<int>(size); int numBytes = base::checked_cast<int>(size);
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> buf = ScopedJavaLocalRef<jobject> buf =
Java_MediaCodecBridge_getOutputBuffer(env, media_codec(), index); Java_MediaCodecBridge_getOutputBuffer(env, media_codec(), index);

@@ -5,7 +5,7 @@
#include "media/base/audio_bus.h" #include "media/base/audio_bus.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "media/audio/audio_parameters.h" #include "media/audio/audio_parameters.h"
#include "media/base/limits.h" #include "media/base/limits.h"
#include "media/base/vector_math.h" #include "media/base/vector_math.h"
@@ -130,7 +130,7 @@ AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data)
frames_(frames), frames_(frames),
can_set_channel_data_(false) { can_set_channel_data_(false) {
ValidateConfig( ValidateConfig(
base::checked_numeric_cast<int>(channel_data_.size()), frames_); base::checked_cast<int>(channel_data_.size()), frames_);
// Sanity check wrapped vector for alignment and channel count. // Sanity check wrapped vector for alignment and channel count.
for (size_t i = 0; i < channel_data_.size(); ++i) for (size_t i = 0; i < channel_data_.size(); ++i)

@@ -12,7 +12,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/socket/client_socket_handle.h" #include "net/socket/client_socket_handle.h"
@@ -347,10 +347,10 @@ int WebSocketBasicStream::ConvertChunkToFrame(
// header. A check for exact equality can only be used when the whole frame // header. A check for exact equality can only be used when the whole frame
// arrives in one chunk. // arrives in one chunk.
DCHECK_GE(current_frame_header_->payload_length, DCHECK_GE(current_frame_header_->payload_length,
base::checked_numeric_cast<uint64>(chunk_size)); base::checked_cast<uint64>(chunk_size));
DCHECK(!is_first_chunk || !is_final_chunk || DCHECK(!is_first_chunk || !is_final_chunk ||
current_frame_header_->payload_length == current_frame_header_->payload_length ==
base::checked_numeric_cast<uint64>(chunk_size)); base::checked_cast<uint64>(chunk_size));
// Convert the chunk to a complete frame. // Convert the chunk to a complete frame.
*frame = CreateFrame(is_final_chunk, data_buffer); *frame = CreateFrame(is_final_chunk, data_buffer);

@@ -9,7 +9,7 @@
#include "base/basictypes.h" // for size_t #include "base/basictypes.h" // for size_t
#include "base/bind.h" #include "base/bind.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "net/base/big_endian.h" #include "net/base/big_endian.h"
@@ -190,7 +190,7 @@ void WebSocketChannel::SendFrame(bool fin,
NOTREACHED() << "SendFrame() called in state " << state_; NOTREACHED() << "SendFrame() called in state " << state_;
return; return;
} }
if (data.size() > base::checked_numeric_cast<size_t>(current_send_quota_)) { if (data.size() > base::checked_cast<size_t>(current_send_quota_)) {
AllowUnused(FailChannel(SEND_GOING_AWAY, AllowUnused(FailChannel(SEND_GOING_AWAY,
kWebSocketMuxErrorSendQuotaViolation, kWebSocketMuxErrorSendQuotaViolation,
"Send quota exceeded")); "Send quota exceeded"));

@@ -18,7 +18,6 @@
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/safe_numerics.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"

@@ -4,7 +4,7 @@
#include "ppapi/host/error_conversion.h" #include "ppapi/host/error_conversion.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
@@ -13,7 +13,7 @@ namespace host {
int32_t NetErrorToPepperError(int net_error) { int32_t NetErrorToPepperError(int net_error) {
if (net_error > 0) if (net_error > 0)
return base::checked_numeric_cast<int32_t>(net_error); return base::checked_cast<int32_t>(net_error);
switch (net_error) { switch (net_error) {
case net::OK: case net::OK:

@@ -8,7 +8,7 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/md5.h" #include "base/md5.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "printing/metafile.h" #include "printing/metafile.h"
#include "printing/metafile_impl.h" #include "printing/metafile_impl.h"
@@ -73,7 +73,7 @@ bool Image::SaveToPng(const base::FilePath& filepath) const {
int write_bytes = file_util::WriteFile( int write_bytes = file_util::WriteFile(
filepath, filepath,
reinterpret_cast<char*>(&*compressed.begin()), reinterpret_cast<char*>(&*compressed.begin()),
base::checked_numeric_cast<int>(compressed.size())); base::checked_cast<int>(compressed.size()));
success = (write_bytes == static_cast<int>(compressed.size())); success = (write_bytes == static_cast<int>(compressed.size()));
DCHECK(success); DCHECK(success);
} }
@@ -152,7 +152,7 @@ bool Image::LoadMetafile(const std::string& data) {
DCHECK(!data.empty()); DCHECK(!data.empty());
NativeMetafile metafile; NativeMetafile metafile;
if (!metafile.InitFromData(data.data(), if (!metafile.InitFromData(data.data(),
base::checked_numeric_cast<uint32>(data.size()))) base::checked_cast<uint32>(data.size())))
return false; return false;
return LoadMetafile(metafile); return LoadMetafile(metafile);
} }

@@ -8,8 +8,8 @@
#include "base/file_descriptor_posix.h" #include "base/file_descriptor_posix.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/numerics/safe_conversions.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/safe_numerics.h"
#include "skia/ext/refptr.h" #include "skia/ext/refptr.h"
#include "skia/ext/vector_platform_device_skia.h" #include "skia/ext/vector_platform_device_skia.h"
#include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkData.h"
@@ -112,7 +112,7 @@ bool PdfMetafileSkia::FinishDocument() {
} }
uint32 PdfMetafileSkia::GetDataSize() const { uint32 PdfMetafileSkia::GetDataSize() const {
return base::checked_numeric_cast<uint32>(data_->pdf_stream_.getOffset()); return base::checked_cast<uint32>(data_->pdf_stream_.getOffset());
} }
bool PdfMetafileSkia::GetData(void* dst_buffer, bool PdfMetafileSkia::GetData(void* dst_buffer,
@@ -241,7 +241,7 @@ PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() {
PdfMetafileSkia* metafile = new PdfMetafileSkia; PdfMetafileSkia* metafile = new PdfMetafileSkia;
metafile->InitFromData(data->bytes(), metafile->InitFromData(data->bytes(),
base::checked_numeric_cast<uint32>(data->size())); base::checked_cast<uint32>(data->size()));
return metafile; return metafile;
} }

@@ -4,7 +4,7 @@
#include "printing/print_destination_interface.h" #include "printing/print_destination_interface.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/win/metro.h" #include "base/win/metro.h"
#include "win8/util/win8_util.h" #include "win8/util/win8_util.h"
@@ -35,7 +35,7 @@ class PrintDestinationWin : public PrintDestinationInterface {
size_t content_size) { size_t content_size) {
if (metro_set_print_page_content_) if (metro_set_print_page_content_)
metro_set_print_page_content_(page_number - 1, content, metro_set_print_page_content_(page_number - 1, content,
base::checked_numeric_cast<UINT32>(content_size)); base::checked_cast<UINT32>(content_size));
} }
private: private:
typedef void (*MetroSetPrintPageCount)(INT); typedef void (*MetroSetPrintPageCount)(INT);

@@ -20,8 +20,8 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/process/memory.h" #include "base/process/memory.h"
#include "base/safe_numerics.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "tools/imagediff/image_diff_png.h" #include "tools/imagediff/image_diff_png.h"
@@ -386,7 +386,7 @@ int DiffImages(const base::FilePath& file1, const base::FilePath& file2,
diff_image.w() * 4, &png_encoding); diff_image.w() * 4, &png_encoding);
if (file_util::WriteFile(out_file, if (file_util::WriteFile(out_file,
reinterpret_cast<char*>(&png_encoding.front()), reinterpret_cast<char*>(&png_encoding.front()),
base::checked_numeric_cast<int>(png_encoding.size())) < 0) base::checked_cast<int>(png_encoding.size())) < 0)
return kStatusError; return kStatusError;
return kStatusDifferent; return kStatusDifferent;

@@ -7,8 +7,8 @@
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
#include <shlobj.h>
#include <shellapi.h> #include <shellapi.h>
#include <shlobj.h>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/bind.h" #include "base/bind.h"
@@ -16,7 +16,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
@@ -518,8 +518,8 @@ void Clipboard::ReadHTML(ClipboardType type,
offsets.push_back(end_index - html_start); offsets.push_back(end_index - html_start);
markup->assign(base::UTF8ToUTF16AndAdjustOffsets(cf_html.data() + html_start, markup->assign(base::UTF8ToUTF16AndAdjustOffsets(cf_html.data() + html_start,
&offsets)); &offsets));
*fragment_start = base::checked_numeric_cast<uint32>(offsets[0]); *fragment_start = base::checked_cast<uint32>(offsets[0]);
*fragment_end = base::checked_numeric_cast<uint32>(offsets[1]); *fragment_end = base::checked_cast<uint32>(offsets[1]);
} }
void Clipboard::ReadRTF(ClipboardType type, std::string* result) const { void Clipboard::ReadRTF(ClipboardType type, std::string* result) const {

@@ -7,7 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "cc/output/copy_output_request.h" #include "cc/output/copy_output_request.h"
#include "cc/output/copy_output_result.h" #include "cc/output/copy_output_result.h"
@@ -85,7 +85,7 @@ scoped_refptr<base::RefCountedBytes> ScaleRotateAndEncodeBitmap(
if (!gfx::PNGCodec::Encode(pixels, if (!gfx::PNGCodec::Encode(pixels,
gfx::PNGCodec::FORMAT_BGRA, gfx::PNGCodec::FORMAT_BGRA,
gfx::Size(bitmap.width(), bitmap.height()), gfx::Size(bitmap.width(), bitmap.height()),
base::checked_numeric_cast<int>(bitmap.rowBytes()), base::checked_cast<int>(bitmap.rowBytes()),
true, true,
std::vector<gfx::PNGCodec::Comment>(), std::vector<gfx::PNGCodec::Comment>(),
&png_data->data())) { &png_data->data())) {

@@ -8,7 +8,7 @@
#include <windows.graphics.display.h> #include <windows.graphics.display.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
namespace { namespace {
@@ -253,7 +253,7 @@ STDMETHODIMP PrintDocumentSource::Paginate(uint32 page,
return S_FALSE; return S_FALSE;
hr = dxgi_preview_target_->SetJobPageCount( hr = dxgi_preview_target_->SetJobPageCount(
PageCountType::FinalPageCount, PageCountType::FinalPageCount,
base::checked_numeric_cast<UINT32>(page_count)); base::checked_cast<UINT32>(page_count));
if (FAILED(hr)) { if (FAILED(hr)) {
LOG(ERROR) << "Failed to SetJobPageCount " << std::hex << hr; LOG(ERROR) << "Failed to SetJobPageCount " << std::hex << hr;
return hr; return hr;

@@ -9,7 +9,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/safe_numerics.h" #include "base/numerics/safe_conversions.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "win8/metro_driver/chrome_app_view.h" #include "win8/metro_driver/chrome_app_view.h"
#include "win8/metro_driver/winrt_utils.h" #include "win8/metro_driver/winrt_utils.h"
@@ -474,7 +474,7 @@ void MetroSetPrintPageContent(size_t page_number,
if (metafile_stream.Get() != NULL) { if (metafile_stream.Get() != NULL) {
ULONG bytes_written = 0; ULONG bytes_written = 0;
hr = metafile_stream->Write(data, hr = metafile_stream->Write(data,
base::checked_numeric_cast<ULONG>(data_size), base::checked_cast<ULONG>(data_size),
&bytes_written); &bytes_written);
LOG_IF(ERROR, FAILED(hr)) << "Failed to Write to Stream " << std::hex << hr; LOG_IF(ERROR, FAILED(hr)) << "Failed to Write to Stream " << std::hex << hr;
DCHECK(bytes_written == data_size); DCHECK(bytes_written == data_size);