summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-02 08:26:30 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-02 08:26:30 +0000
commit08e710346ccee33e92e1ffc27c0d4bbe9d311b23 (patch)
treef38488b586a93de7a3280d5afaf5e923de13daf3 /base
parent7fe28657c7aad242cb99659e48400ea7ef0b04f2 (diff)
downloadchromium_src-08e710346ccee33e92e1ffc27c0d4bbe9d311b23.zip
chromium_src-08e710346ccee33e92e1ffc27c0d4bbe9d311b23.tar.gz
chromium_src-08e710346ccee33e92e1ffc27c0d4bbe9d311b23.tar.bz2
Fix scoped_ptr<T[]> to disallow construction and reset from NULL.
BUG=171118 Review URL: https://codereview.chromium.org/12041050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180253 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/memory/scoped_ptr.h2
-rw-r--r--base/memory/scoped_ptr_unittest.nc26
-rw-r--r--base/move.h2
-rw-r--r--base/nix/mime_util_xdg.cc3
-rw-r--r--base/values.cc1
5 files changed, 30 insertions, 4 deletions
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h
index b1d6149..d86c249 100644
--- a/base/memory/scoped_ptr.h
+++ b/base/memory/scoped_ptr.h
@@ -526,10 +526,12 @@ class scoped_ptr<T[], D> {
// call delete[] on an array whose static type does not match its dynamic
// type.
template <typename U> explicit scoped_ptr(U* array);
+ explicit scoped_ptr(int disallow_construction_from_null);
// Disable reset() from any type other than element_type*, for the same
// reasons as the constructor above.
template <typename U> void reset(U* array);
+ void reset(int disallow_reset_from_null);
// Forbid comparison of scoped_ptr types. If U != T, it totally
// doesn't make sense, and if U == T, it still doesn't make sense
diff --git a/base/memory/scoped_ptr_unittest.nc b/base/memory/scoped_ptr_unittest.nc
index ecbeb4e..2e2a3e5 100644
--- a/base/memory/scoped_ptr_unittest.nc
+++ b/base/memory/scoped_ptr_unittest.nc
@@ -68,6 +68,32 @@ void WontCompile() {
scoped_ptr<int[]> b(a.Pass());
}
+#elif defined(NCTEST_NO_CONSTRUCT_SCOPED_PTR_ARRAY_FROM_NULL) // [r"is ambiguous"]
+
+void WontCompile() {
+ scoped_ptr<int[]> x(NULL);
+}
+
+#elif defined(NCTEST_NO_CONSTRUCT_SCOPED_PTR_ARRAY_FROM_DERIVED) // [r"is private"]
+
+void WontCompile() {
+ scoped_ptr<Parent[]> x(new Child[1]);
+}
+
+#elif defined(NCTEST_NO_RESET_SCOPED_PTR_ARRAY_FROM_NULL) // [r"is ambiguous"]
+
+void WontCompile() {
+ scoped_ptr<int[]> x;
+ x.reset(NULL);
+}
+
+#elif defined(NCTEST_NO_RESET_SCOPED_PTR_ARRAY_FROM_DERIVED) // [r"is private"]
+
+void WontCompile() {
+ scoped_ptr<Parent[]> x;
+ x.reset(new Child[1]);
+}
+
#elif defined(NCTEST_NO_DELETER_REFERENCE) // [r"fails to be a struct or class type"]
struct Deleter {
diff --git a/base/move.h b/base/move.h
index 7fcb8dd..2bb70ab 100644
--- a/base/move.h
+++ b/base/move.h
@@ -194,7 +194,7 @@
#define MOVE_ONLY_TYPE_FOR_CPP_03(type, rvalue_type) \
private: \
struct rvalue_type { \
- rvalue_type(type* object) : object(object) {} \
+ explicit rvalue_type(type* object) : object(object) {} \
type* object; \
}; \
type(type&); \
diff --git a/base/nix/mime_util_xdg.cc b/base/nix/mime_util_xdg.cc
index 2e0dbee..329102a 100644
--- a/base/nix/mime_util_xdg.cc
+++ b/base/nix/mime_util_xdg.cc
@@ -165,8 +165,7 @@ class IconTheme {
};
IconTheme::IconTheme(const std::string& name)
- : index_theme_loaded_(false),
- info_array_(NULL) {
+ : index_theme_loaded_(false) {
base::ThreadRestrictions::AssertIOAllowed();
// Iterate on all icon directories to find directories of the specified
// theme and load the first encountered index.theme.
diff --git a/base/values.cc b/base/values.cc
index 9228ca9..3712d46 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -304,7 +304,6 @@ bool StringValue::Equals(const Value* other) const {
BinaryValue::BinaryValue()
: Value(TYPE_BINARY),
- buffer_(NULL),
size_(0) {
}