File tree 2 files changed +15
-1
lines changed 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) {
912
912
if (newSize == 0 )
913
913
clear ();
914
914
else if (newSize > oldSize)
915
- this ->operator [](newSize - 1 );
915
+ for (ArrayIndex i = oldSize; i < newSize; ++i)
916
+ (*this )[i];
916
917
else {
917
918
for (ArrayIndex index = newSize; index < oldSize; ++index ) {
918
919
value_.map_ ->erase (index );
Original file line number Diff line number Diff line change 12
12
13
13
#include " fuzz.h"
14
14
#include " jsontest.h"
15
+ #include < algorithm>
15
16
#include < cmath>
16
17
#include < cstring>
17
18
#include < functional>
24
25
#include < memory>
25
26
#include < sstream>
26
27
#include < string>
28
+ #include < vector>
27
29
28
30
using CharReaderPtr = std::unique_ptr<Json::CharReader>;
29
31
@@ -347,6 +349,17 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, resizeArray) {
347
349
JSONTEST_ASSERT_EQUAL (array.size (), 0 );
348
350
}
349
351
}
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
+
350
363
JSONTEST_FIXTURE_LOCAL (ValueTest, getArrayValue) {
351
364
Json::Value array;
352
365
for (Json::ArrayIndex i = 0 ; i < 5 ; i++)
You can’t perform that action at this time.
0 commit comments