File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -912,7 +912,8 @@ void Value::resize(ArrayIndex newSize) {
912912 if (newSize == 0 )
913913 clear ();
914914 else if (newSize > oldSize)
915- this ->operator [](newSize - 1 );
915+ for (ArrayIndex i = oldSize; i < newSize; ++i)
916+ (*this )[i];
916917 else {
917918 for (ArrayIndex index = newSize; index < oldSize; ++index) {
918919 value_.map_ ->erase (index);
Original file line number Diff line number Diff line change 1212
1313#include " fuzz.h"
1414#include " jsontest.h"
15+ #include < algorithm>
1516#include < cmath>
1617#include < cstring>
1718#include < functional>
2425#include < memory>
2526#include < sstream>
2627#include < string>
28+ #include < vector>
2729
2830using CharReaderPtr = std::unique_ptr<Json::CharReader>;
2931
@@ -347,6 +349,17 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, resizeArray) {
347349 JSONTEST_ASSERT_EQUAL (array.size (), 0 );
348350 }
349351}
352+
353+ JSONTEST_FIXTURE_LOCAL (ValueTest, resizePopulatesAllMissingElements) {
354+ int n = 10 ;
355+ Json::Value v;
356+ v.resize (n);
357+ JSONTEST_ASSERT_EQUAL (n, v.size ());
358+ JSONTEST_ASSERT_EQUAL (n, std::distance (v.begin (), v.end ()));
359+ for (const Json::Value& e : v)
360+ JSONTEST_ASSERT_EQUAL (e, Json::Value{});
361+ }
362+
350363JSONTEST_FIXTURE_LOCAL (ValueTest, getArrayValue) {
351364 Json::Value array;
352365 for (Json::ArrayIndex i = 0 ; i < 5 ; i++)
You can’t perform that action at this time.
0 commit comments