Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2212)

Unified Diff: base/ref_counted_memory.h

Issue 333048: Fix an exception in the ref counted data. This appeares as a crash on startip... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/ref_counted_memory.h
===================================================================
--- base/ref_counted_memory.h (revision 30122)
+++ base/ref_counted_memory.h (working copy)
@@ -19,7 +19,8 @@
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 @@
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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698