diff options
-rw-r--r-- | android_webview/browser/scoped_app_gl_state_restore.cc | 4 | ||||
-rw-r--r-- | chromeos/network/network_cert_migrator.cc | 2 | ||||
-rw-r--r-- | chromeos/network/network_change_notifier_chromeos_unittest.cc | 2 | ||||
-rw-r--r-- | crypto/hmac_unittest.cc | 6 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_uuid_unittest.cc | 2 | ||||
-rw-r--r-- | device/hid/hid_report_descriptor_unittest.cc | 10 | ||||
-rw-r--r-- | gin/converter_unittest.cc | 6 | ||||
-rw-r--r-- | google_apis/drive/drive_api_url_generator_unittest.cc | 6 | ||||
-rw-r--r-- | mojo/examples/window_manager/debug_panel.cc | 4 | ||||
-rw-r--r-- | third_party/cld/base/basictypes.h | 49 | ||||
-rw-r--r-- | tools/gn/label_unittest.cc | 2 |
11 files changed, 23 insertions, 70 deletions
diff --git a/android_webview/browser/scoped_app_gl_state_restore.cc b/android_webview/browser/scoped_app_gl_state_restore.cc index a36e061..43bd8aa 100644 --- a/android_webview/browser/scoped_app_gl_state_restore.cc +++ b/android_webview/browser/scoped_app_gl_state_restore.cc @@ -273,7 +273,7 @@ ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl( glBindVertexArrayOES(0); } - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib_); ++i) { + for (size_t i = 0; i < arraysize(vertex_attrib_); ++i) { glGetVertexAttribiv( i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &vertex_attrib_[i].enabled); glGetVertexAttribiv( @@ -309,7 +309,7 @@ ScopedAppGLStateRestoreImpl::~ScopedAppGLStateRestoreImpl() { if (g_supports_oes_vertex_array_object) glBindVertexArrayOES(0); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib_); ++i) { + for (size_t i = 0; i < arraysize(vertex_attrib_); ++i) { glBindBuffer(GL_ARRAY_BUFFER, vertex_attrib_[i].vertex_attrib_array_buffer_binding); glVertexAttribPointer(i, diff --git a/chromeos/network/network_cert_migrator.cc b/chromeos/network/network_cert_migrator.cc index 1b50820..613d46a 100644 --- a/chromeos/network/network_cert_migrator.cc +++ b/chromeos/network/network_cert_migrator.cc @@ -210,7 +210,7 @@ class NetworkCertMigrator::MigrationTask shill::kOpenVPNCaCertPemProperty, UMA_NETWORK_TYPE_OPENVPN }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNssPemMap); ++i) { + for (size_t i = 0; i < arraysize(kNssPemMap); ++i) { const base::DictionaryValue* dict = &shill_properties; if (kNssPemMap[i].read_prefix) { shill_properties.GetDictionaryWithoutPathExpansion( diff --git a/chromeos/network/network_change_notifier_chromeos_unittest.cc b/chromeos/network/network_change_notifier_chromeos_unittest.cc index 04d549f..e1b8d78 100644 --- a/chromeos/network/network_change_notifier_chromeos_unittest.cc +++ b/chromeos/network/network_change_notifier_chromeos_unittest.cc @@ -92,7 +92,7 @@ TEST(NetworkChangeNotifierChromeosTest, ConnectionTypeFromShill) { NetworkChangeNotifier::CONNECTION_2G } }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(type_mappings); ++i) { + for (size_t i = 0; i < arraysize(type_mappings); ++i) { NetworkChangeNotifier::ConnectionType type = NetworkChangeNotifierChromeos::ConnectionTypeFromShill( type_mappings[i].shill_type, type_mappings[i].technology); diff --git a/crypto/hmac_unittest.cc b/crypto/hmac_unittest.cc index 174c323..91eccd6 100644 --- a/crypto/hmac_unittest.cc +++ b/crypto/hmac_unittest.cc @@ -142,7 +142,7 @@ TEST(HMACTest, RFC2202TestCases) { "\xBB\xFF\x1A\x91" } }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + for (size_t i = 0; i < arraysize(cases); ++i) { crypto::HMAC hmac(crypto::HMAC::SHA1); ASSERT_TRUE(hmac.Init(reinterpret_cast<const unsigned char*>(cases[i].key), cases[i].key_len)); @@ -239,7 +239,7 @@ TEST(HMACTest, HMACObjectReuse) { ASSERT_TRUE( hmac.Init(reinterpret_cast<const unsigned char*>(kSimpleKey), kSimpleKeyLength)); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSimpleHmacCases); ++i) { + for (size_t i = 0; i < arraysize(kSimpleHmacCases); ++i) { std::string data_string(kSimpleHmacCases[i].data, kSimpleHmacCases[i].data_len); unsigned char digest[kSHA1DigestSize]; @@ -254,7 +254,7 @@ TEST(HMACTest, Verify) { hmac.Init(reinterpret_cast<const unsigned char*>(kSimpleKey), kSimpleKeyLength)); const char empty_digest[kSHA1DigestSize] = { 0 }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSimpleHmacCases); ++i) { + for (size_t i = 0; i < arraysize(kSimpleHmacCases); ++i) { // Expected results EXPECT_TRUE(hmac.Verify( base::StringPiece(kSimpleHmacCases[i].data, diff --git a/device/bluetooth/bluetooth_uuid_unittest.cc b/device/bluetooth/bluetooth_uuid_unittest.cc index c59ab1c..380d151 100644 --- a/device/bluetooth/bluetooth_uuid_unittest.cc +++ b/device/bluetooth/bluetooth_uuid_unittest.cc @@ -95,7 +95,7 @@ TEST(BluetoothUUIDTest, BluetoothUUID_CaseInsensitive) { { "00001aBc-0000-1000-8000-00805F9b34fB", k128Bit }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { + for (size_t i = 0; i < arraysize(test_cases); ++i) { SCOPED_TRACE("Input UUID: " + test_cases[i].input_uuid); BluetoothUUID uuid(test_cases[i].input_uuid); EXPECT_TRUE(uuid.IsValid()); diff --git a/device/hid/hid_report_descriptor_unittest.cc b/device/hid/hid_report_descriptor_unittest.cc index 681459c..dc0f96a 100644 --- a/device/hid/hid_report_descriptor_unittest.cc +++ b/device/hid/hid_report_descriptor_unittest.cc @@ -356,7 +356,7 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_Digitizer) { digitizer.report_ids.insert(3); HidCollectionInfo expected[] = {digitizer}; ValidateDetails(std::vector<HidCollectionInfo>( - expected, expected + ARRAYSIZE_UNSAFE(expected)), + expected, expected + arraysize(expected)), true, 6, 0, @@ -370,7 +370,7 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_Keyboard) { keyboard.usage = HidUsageAndPage(0x06, HidUsageAndPage::kPageGenericDesktop); HidCollectionInfo expected[] = {keyboard}; ValidateDetails(std::vector<HidCollectionInfo>( - expected, expected + ARRAYSIZE_UNSAFE(expected)), + expected, expected + arraysize(expected)), false, 8, 1, @@ -389,7 +389,7 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_Monitor) { monitor.report_ids.insert(5); HidCollectionInfo expected[] = {monitor}; ValidateDetails(std::vector<HidCollectionInfo>( - expected, expected + ARRAYSIZE_UNSAFE(expected)), + expected, expected + arraysize(expected)), true, 0, 0, @@ -403,7 +403,7 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_Mouse) { mouse.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageGenericDesktop); HidCollectionInfo expected[] = {mouse}; ValidateDetails(std::vector<HidCollectionInfo>( - expected, expected + ARRAYSIZE_UNSAFE(expected)), + expected, expected + arraysize(expected)), false, 3, 0, @@ -426,7 +426,7 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_LogitechUnifyingReceiver) { HidCollectionInfo expected[] = {hidpp_short, hidpp_long, hidpp_dj}; ValidateDetails(std::vector<HidCollectionInfo>( - expected, expected + ARRAYSIZE_UNSAFE(expected)), + expected, expected + arraysize(expected)), true, 31, 31, diff --git a/gin/converter_unittest.cc b/gin/converter_unittest.cc index 791d7e6..f8011d6 100644 --- a/gin/converter_unittest.cc +++ b/gin/converter_unittest.cc @@ -55,7 +55,7 @@ TEST_F(ConverterTest, Bool) { { Undefined(instance_->isolate()).As<Value>(), false }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { + for (size_t i = 0; i < arraysize(test_data); ++i) { bool result = false; EXPECT_TRUE(Converter<bool>::FromV8(instance_->isolate(), test_data[i].input, &result)); @@ -72,7 +72,7 @@ TEST_F(ConverterTest, Int32) { HandleScope handle_scope(instance_->isolate()); int test_data_to[] = {-1, 0, 1}; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data_to); ++i) { + for (size_t i = 0; i < arraysize(test_data_to); ++i) { EXPECT_TRUE(Converter<int32_t>::ToV8(instance_->isolate(), test_data_to[i]) ->StrictEquals( Integer::New(instance_->isolate(), test_data_to[i]))); @@ -98,7 +98,7 @@ TEST_F(ConverterTest, Int32) { { v8::Undefined(instance_->isolate()).As<Value>(), false, 0 }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data_from); ++i) { + for (size_t i = 0; i < arraysize(test_data_from); ++i) { int32_t result = std::numeric_limits<int32_t>::min(); bool success = Converter<int32_t>::FromV8(instance_->isolate(), test_data_from[i].input, &result); diff --git a/google_apis/drive/drive_api_url_generator_unittest.cc b/google_apis/drive/drive_api_url_generator_unittest.cc index 557a0af..8ebc175 100644 --- a/google_apis/drive/drive_api_url_generator_unittest.cc +++ b/google_apis/drive/drive_api_url_generator_unittest.cc @@ -97,7 +97,7 @@ TEST_F(DriveApiUrlGeneratorTest, GetFilePatchUrl) { { true, false, "?setModifiedDate=true&updateViewedDate=false" }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) { + for (size_t i = 0; i < arraysize(kTestPatterns); ++i) { EXPECT_EQ( "https://www.googleapis.com/drive/v2/files/0ADK06pfg" + kTestPatterns[i].expected_query, @@ -188,7 +188,7 @@ TEST_F(DriveApiUrlGeneratorTest, GetFilesListUrl) { { 10, "token", "query", "?maxResults=10&pageToken=token&q=query" }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) { + for (size_t i = 0; i < arraysize(kTestPatterns); ++i) { EXPECT_EQ( "https://www.googleapis.com/drive/v2/files" + kTestPatterns[i].expected_query, @@ -288,7 +288,7 @@ TEST_F(DriveApiUrlGeneratorTest, GetChangesListUrl) { "&startChangeId=12345" }, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) { + for (size_t i = 0; i < arraysize(kTestPatterns); ++i) { EXPECT_EQ( "https://www.googleapis.com/drive/v2/changes" + kTestPatterns[i].expected_query, diff --git a/mojo/examples/window_manager/debug_panel.cc b/mojo/examples/window_manager/debug_panel.cc index 7d86cfe..7551fb4 100644 --- a/mojo/examples/window_manager/debug_panel.cc +++ b/mojo/examples/window_manager/debug_panel.cc @@ -99,7 +99,7 @@ void DebugPanel::Layout(views::View* view) { navigation_target_new_, navigation_target_source_, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(radios); ++i) { + for (size_t i = 0; i < arraysize(radios); ++i) { radios[i]->SetBounds(kControlBorderInset, y, w, radios[i]->GetPreferredSize().height()); y += radios[i]->height(); @@ -111,7 +111,7 @@ void DebugPanel::Layout(views::View* view) { close_last_, cross_app_, }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(buttons); ++i) { + for (size_t i = 0; i < arraysize(buttons); ++i) { buttons[i]->SetBounds(kControlBorderInset, y, w, buttons[i]->GetPreferredSize().height()); y += buttons[i]->height(); diff --git a/third_party/cld/base/basictypes.h b/third_party/cld/base/basictypes.h index 287d1c2..af28256 100644 --- a/third_party/cld/base/basictypes.h +++ b/third_party/cld/base/basictypes.h @@ -98,12 +98,6 @@ const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF)); // The expression is a compile-time constant, and therefore can be // used in defining new arrays, for example. If you use arraysize on // a pointer by mistake, you will get a compile-time error. -// -// One caveat is that arraysize() doesn't accept any array of an -// anonymous type or a type defined inside a function. In these rare -// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is -// due to a limitation in C++'s template system. The limitation might -// eventually be removed, but it hasn't happened yet. // This template function declaration is used in defining arraysize. // Note that the function doesn't need an implementation, as we only @@ -121,47 +115,6 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; #define arraysize(array) (sizeof(ArraySizeHelper(array))) -// ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, -// but can be used on anonymous types or types defined inside -// functions. It's less safe than arraysize as it accepts some -// (although not all) pointers. Therefore, you should use arraysize -// whenever possible. -// -// The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type -// size_t. -// -// ARRAYSIZE_UNSAFE catches a few type errors. If you see a compiler error -// -// "warning: division by zero in ..." -// -// when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer. -// You should only use ARRAYSIZE_UNSAFE on statically allocated arrays. -// -// The following comments are on the implementation details, and can -// be ignored by the users. -// -// ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in -// the array) and sizeof(*(arr)) (the # of bytes in one array -// element). If the former is divisible by the latter, perhaps arr is -// indeed an array, in which case the division result is the # of -// elements in the array. Otherwise, arr cannot possibly be an array, -// and we generate a compiler error to prevent the code from -// compiling. -// -// Since the size of bool is implementation-defined, we need to cast -// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final -// result has type size_t. -// -// This macro is not perfect as it wrongfully accepts certain -// pointers, namely where the pointer size is divisible by the pointee -// size. Since all our code has to go through a 32-bit compiler, -// where a pointer is 4 bytes, this means all pointers to a type whose -// size is 3 or greater than 4 will be (righteously) rejected. - -#define ARRAYSIZE_UNSAFE(a) \ - ((sizeof(a) / sizeof(*(a))) / \ - static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) - // Use implicit_cast as a safe version of static_cast or const_cast // for upcasting in the type hierarchy (i.e. casting a pointer to Foo @@ -189,7 +142,7 @@ inline To implicit_cast(From const &f) { // expression is true. For example, you could use it to verify the // size of a static array: // -// COMPILE_ASSERT(ARRAYSIZE_UNSAFE(content_type_names) == CONTENT_NUM_TYPES, +// COMPILE_ASSERT(arraysize(content_type_names) == CONTENT_NUM_TYPES, // content_type_names_incorrect_size); // // or to make sure a struct is smaller than a certain size: diff --git a/tools/gn/label_unittest.cc b/tools/gn/label_unittest.cc index 3067ef6..3ffa3f4 100644 --- a/tools/gn/label_unittest.cc +++ b/tools/gn/label_unittest.cc @@ -63,7 +63,7 @@ TEST(Label, Resolve) { Label default_toolchain(SourceDir("//t/"), "d"); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { + for (size_t i = 0; i < arraysize(cases); i++) { const ParseDepStringCase& cur = cases[i]; std::string location, name; |