summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi Sumita <hsumita@chromium.org>2012-06-06 14:05:20 +0900
committerHiroshi Sumita <hsumita@chromium.org>2012-06-06 14:05:20 +0900
commitad58ca3fb07c35eedcaf2edc2e9e7f19c8b46138 (patch)
treea86b81e1e428f969855bc266454d7b60ffe77bbb
parent1b0f6aab98c479873a278b50fce1ff673e3d6564 (diff)
downloadpyzy-ad58ca3fb07c35eedcaf2edc2e9e7f19c8b46138.tar.gz
Fixes a bug caused by a reallocation on vector.
BUG=Database::query crashes on some situation TEST=Manual Review URL: https://codereview.appspot.com/6295043
-rw-r--r--src/PyZyDatabase.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/PyZyDatabase.cc b/src/PyZyDatabase.cc
index 064f54a..c9769b2 100644
--- a/src/PyZyDatabase.cc
+++ b/src/PyZyDatabase.cc
@@ -51,6 +51,9 @@ public:
void double_ (void) {
size_t i = size ();
+ // To avoid a invalid referece caused by a memory reallocation, which
+ // may occur on push_back, we call reserve here.
+ reserve (i * 2);
do {
push_back (at (--i));
} while (i > 0);
@@ -58,8 +61,11 @@ public:
void triple (void) {
size_t i = size ();
+ // To avoid a invalid referece caused by a memory reallocation, which
+ // may occur on push_back, we call reserve here.
+ reserve (i * 3);
do {
- const std::string & value = std::vector<std::string>::at (--i);
+ const std::string & value = at (--i);
push_back (value);
push_back (value);
} while (i > 0);