diff options
author | Marc Laukien <marc@zeroc.com> | 2004-01-26 23:10:40 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2004-01-26 23:10:40 +0000 |
commit | 921c8801fac45df8082d7c4621ca813199cbc150 (patch) | |
tree | 3b136b405318eb89de07022226a6233dc6070268 /cpp/src | |
parent | <iterate> fix (diff) | |
download | ice-921c8801fac45df8082d7c4621ca813199cbc150.tar.bz2 ice-921c8801fac45df8082d7c4621ca813199cbc150.tar.xz ice-921c8801fac45df8082d7c4621ca813199cbc150.zip |
fix
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 12 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 22 |
2 files changed, 22 insertions, 12 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index 6b758cb631e..0987c83efbe 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -1106,12 +1106,16 @@ IceInternal::BasicStream::read(vector<string>& v) Int sz; readSize(sz); v.clear(); - v.reserve(sz); + + // + // Don't use v.resize(sz) or v.reserve(sz) here, as it cannot be + // checked whether sz is a reasonable value. + // + while(sz--) { - string s; - read(s); - v.push_back(s); + v.resize(v.size() + 1); + read(v.back()); } } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 76f69cfce5e..ae589c64469 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -663,15 +663,21 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) C << nl << "::Ice::Int sz;"; C << nl << "__is->readSize(sz);"; // - // ML: - // Don't use v.resize(sz) or v.reserve(sz) here, as it cannot - // be checked whether sz is a reasonable value. + // ML: Don't use v.resize(sz) or v.reserve(sz) here, as it + // cannot be checked whether sz is a reasonable value. // - // Michi: I don't think it matters -- if the size is unreasonable, we just fall over after having - // unmarshaled a whole lot of stuff instead of falling over straight away. I need to preallocate - // space for the entire sequence up-front because, otherwise, resizing the sequence may move it in - // memory and cause the wrong locations to be patched for classes. Also, doing a single large allocation - // up-front will be faster the repeatedly growing the vector. + // Michi: I don't think it matters -- if the size is + // unreasonable, we just fall over after having unmarshaled a + // whole lot of stuff instead of falling over straight away. I + // need to preallocate space for the entire sequence up-front + // because, otherwise, resizing the sequence may move it in + // memory and cause the wrong locations to be patched for + // classes. Also, doing a single large allocation up-front + // will be faster the repeatedly growing the vector. + // + // ML: It does matter. If we resize to a huge number, the + // program will crash. If we don't, but just loop, then we + // will eventually get an UnmarshalOutOfBoundsException. // C << nl << "v.resize(sz);"; C << nl << "for(int i = 0; i < sz; ++i)"; |