diff options
author | Hiroshi Sumita <hsumita@chromium.org> | 2012-06-06 14:05:20 +0900 |
---|---|---|
committer | Hiroshi Sumita <hsumita@chromium.org> | 2012-06-06 14:05:20 +0900 |
commit | ad58ca3fb07c35eedcaf2edc2e9e7f19c8b46138 (patch) | |
tree | a86b81e1e428f969855bc266454d7b60ffe77bbb | |
parent | 1b0f6aab98c479873a278b50fce1ff673e3d6564 (diff) | |
download | pyzy-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.cc | 8 |
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); |