summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-02 12:57:53 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-02 12:57:53 +0000
commite15c8e011e4a6131e7e2745c5d75d0c3f1a5d685 (patch)
tree4fdc430f814d604202d329bc41fb3cde9deb941c /net
parentdeab34b9ae3023686b243e6aab9d4f790400bf88 (diff)
downloadchromium_src-e15c8e011e4a6131e7e2745c5d75d0c3f1a5d685.zip
chromium_src-e15c8e011e4a6131e7e2745c5d75d0c3f1a5d685.tar.gz
chromium_src-e15c8e011e4a6131e7e2745c5d75d0c3f1a5d685.tar.bz2
Try to consistently use arraysize() with strlcpy().
For a char*, sizeof() == arraysize(), so there is nothing wrong with the current code. However I think it's important to be clear that the lcpy() functions work in characters and not bytes. The danger would be accidently using sizeof() with wcslcpy, for example copying some code as an example or modifying old code to use a wchar instead of a char. Review URL: http://codereview.chromium.org/17019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7536 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/disk_cache/backend_unittest.cc7
-rw-r--r--net/disk_cache/entry_unittest.cc19
-rw-r--r--net/disk_cache/mapped_file_unittest.cc5
3 files changed, 17 insertions, 14 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 701de4b..6d3dfb3 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/platform_thread.h"
@@ -162,17 +163,17 @@ void DiskCacheBackendTest::BackendKeying() {
entry2->Close();
char buffer[30];
- base::strlcpy(buffer, kName1, sizeof(buffer));
+ base::strlcpy(buffer, kName1, arraysize(buffer));
ASSERT_TRUE(cache_->OpenEntry(buffer, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
- base::strlcpy(buffer + 1, kName1, sizeof(buffer) - 1);
+ base::strlcpy(buffer + 1, kName1, arraysize(buffer) - 1);
ASSERT_TRUE(cache_->OpenEntry(buffer + 1, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
- base::strlcpy(buffer + 3, kName1, sizeof(buffer) - 3);
+ base::strlcpy(buffer + 3, kName1, arraysize(buffer) - 3);
ASSERT_TRUE(cache_->OpenEntry(buffer + 3, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index abd1008..4a93151 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/basictypes.h"
#include "base/platform_thread.h"
#include "base/timer.h"
#include "base/string_util.h"
@@ -42,7 +43,7 @@ void DiskCacheEntryTest::InternalSyncIO() {
char buffer1[10];
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
- base::strlcpy(buffer1, "the data", sizeof(buffer1));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, sizeof(buffer1), NULL, false));
memset(buffer1, 0, sizeof(buffer1));
EXPECT_EQ(10, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
@@ -51,7 +52,7 @@ void DiskCacheEntryTest::InternalSyncIO() {
char buffer2[5000];
char buffer3[10000] = {0};
CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
- base::strlcpy(buffer2, "The really big data goes here", sizeof(buffer2));
+ base::strlcpy(buffer2, "The really big data goes here", arraysize(buffer2));
EXPECT_EQ(5000, entry1->WriteData(1, 1500, buffer2, sizeof(buffer2), NULL,
false));
memset(buffer2, 0, sizeof(buffer2));
@@ -117,7 +118,7 @@ void DiskCacheEntryTest::InternalAsyncIO() {
CacheTestFillBuffer(buffer3, sizeof(buffer3), false);
EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), &callback1));
- base::strlcpy(buffer1, "the data", sizeof(buffer1));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
int expected = 0;
int ret = entry1->WriteData(0, 0, buffer1, sizeof(buffer1), &callback2,
false);
@@ -135,7 +136,7 @@ void DiskCacheEntryTest::InternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_STREQ("the data", buffer2);
- base::strlcpy(buffer2, "The really big data goes here", sizeof(buffer2));
+ base::strlcpy(buffer2, "The really big data goes here", arraysize(buffer2));
ret = entry1->WriteData(1, 1500, buffer2, sizeof(buffer2), &callback4, false);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
@@ -222,14 +223,14 @@ void DiskCacheEntryTest::ExternalSyncIO() {
char buffer1[17000], buffer2[25000];
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
- base::strlcpy(buffer1, "the data", sizeof(buffer1));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
EXPECT_EQ(17000, entry1->WriteData(0, 0, buffer1, sizeof(buffer1), NULL,
false));
memset(buffer1, 0, sizeof(buffer1));
EXPECT_EQ(17000, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
EXPECT_STREQ("the data", buffer1);
- base::strlcpy(buffer2, "The really big data goes here", sizeof(buffer2));
+ base::strlcpy(buffer2, "The really big data goes here", arraysize(buffer2));
EXPECT_EQ(25000, entry1->WriteData(1, 10000, buffer2, sizeof(buffer2), NULL,
false));
memset(buffer2, 0, sizeof(buffer2));
@@ -287,7 +288,7 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
CacheTestFillBuffer(buffer3, sizeof(buffer3), false);
- base::strlcpy(buffer1, "the data", sizeof(buffer1));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
int ret = entry1->WriteData(0, 0, buffer1, sizeof(buffer1), &callback1,
false);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
@@ -307,7 +308,7 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_STREQ("the data", buffer1);
- base::strlcpy(buffer2, "The really big data goes here", sizeof(buffer2));
+ base::strlcpy(buffer2, "The really big data goes here", arraysize(buffer2));
ret = entry1->WriteData(1, 10000, buffer2, sizeof(buffer2), &callback3,
false);
EXPECT_TRUE(25000 == ret || net::ERR_IO_PENDING == ret);
@@ -465,7 +466,7 @@ void DiskCacheEntryTest::GrowData() {
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
memset(buffer2, 0, sizeof(buffer2));
- base::strlcpy(buffer1, "the data", sizeof(buffer1));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, 10, NULL, false));
EXPECT_EQ(10, entry1->ReadData(0, 0, buffer2, 10, NULL));
EXPECT_STREQ("the data", buffer2);
diff --git a/net/disk_cache/mapped_file_unittest.cc b/net/disk_cache/mapped_file_unittest.cc
index 28eeff5..a9b3754 100644
--- a/net/disk_cache/mapped_file_unittest.cc
+++ b/net/disk_cache/mapped_file_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/string_util.h"
#include "net/disk_cache/disk_cache_test_base.h"
@@ -77,7 +78,7 @@ TEST_F(DiskCacheTest, MappedFile_SyncIO) {
char buffer1[20];
char buffer2[20];
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
- base::strlcpy(buffer1, "the data", sizeof(buffer1));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 8192));
EXPECT_TRUE(file->Read(buffer2, sizeof(buffer2), 8192));
EXPECT_STREQ(buffer1, buffer2);
@@ -100,7 +101,7 @@ TEST_F(DiskCacheTest, MappedFile_AsyncIO) {
char buffer1[20];
char buffer2[20];
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
- base::strlcpy(buffer1, "the data", sizeof(buffer1));
+ base::strlcpy(buffer1, "the data", arraysize(buffer1));
bool completed;
EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 1024 * 1024, &callback,
&completed));