summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-27 16:24:13 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-27 16:24:13 +0000
commit1e7fafc43baf4b1f1bab51c5514e035058f84172 (patch)
treec224b3854592a6af30cc643cd91df6d2678dc2d7 /base
parent6a5670d2fa75f36a9a51eef48e1ed2bd710f36f8 (diff)
downloadchromium_src-1e7fafc43baf4b1f1bab51c5514e035058f84172.zip
chromium_src-1e7fafc43baf4b1f1bab51c5514e035058f84172.tar.gz
chromium_src-1e7fafc43baf4b1f1bab51c5514e035058f84172.tar.bz2
Fix an exception in the ref counted data. This appeares as a crash on startip
onm my profile because I have a bookmarked favicon that exists but is empty. This makes the front() behavior of RefCountedBytes the same as RefCountedStaticMemory, and I documented this as the correct behavior. TEST=none BUG=none Review URL: http://codereview.chromium.org/333048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/ref_counted_memory.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/base/ref_counted_memory.h b/base/ref_counted_memory.h
index ef05abd..30d2917 100644
--- a/base/ref_counted_memory.h
+++ b/base/ref_counted_memory.h
@@ -19,7 +19,8 @@ class RefCountedMemory : public base::RefCountedThreadSafe< RefCountedMemory > {
public:
virtual ~RefCountedMemory() {}
- // Retrieves a pointer to the beginning of the data we point to.
+ // Retrieves a pointer to the beginning of the data we point to. If the data
+ // is empty, this will return NULL.
virtual const unsigned char* front() const = 0;
// Size of the memory pointed to.
@@ -64,7 +65,11 @@ class RefCountedBytes : public RefCountedMemory {
RefCountedBytes(const std::vector<unsigned char>& initializer)
: data(initializer) {}
- virtual const unsigned char* front() const { return &data.front(); }
+ virtual const unsigned char* front() const {
+ // STL will assert if we do front() on an empty vector, but calling code
+ // expects a NULL.
+ return size() ? &data.front() : NULL;
+ }
virtual size_t size() const { return data.size(); }
std::vector<unsigned char> data;