diff options
author | Jamey Hicks <jamey.hicks@nokia.com> | 2011-12-01 11:10:20 -0800 |
---|---|---|
committer | Knoll Lars <lars.knoll@nokia.com> | 2011-12-05 10:12:36 +0100 |
commit | 422fe09794bcbea8d8dc368f77e86113d554f6a6 (patch) | |
tree | 70f9262a84f78211d322eeb2f467f7ec57b9224b | |
parent | b786a71a0b62a125d48bb01175cd4995bdc54229 (diff) |
Fixed a segv for empty arrays.
Change-Id: I3311137ea70031369a0efd51a9d90fd77356967f
Reviewed-by: Knoll Lars <lars.knoll@nokia.com>
-rw-r--r-- | src/qbinaryjson_p.h | 5 | ||||
-rw-r--r-- | tests/auto/tst_qtbinaryjson.cpp | 11 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/qbinaryjson_p.h b/src/qbinaryjson_p.h index 8dee092..e33372b 100644 --- a/src/qbinaryjson_p.h +++ b/src/qbinaryjson_p.h @@ -239,9 +239,10 @@ inline Object *Value::object() const Value *Value::fromArray(const Array *a) { - Value *v = alloc(sizeof(Value) + a->size); + int size = a ? a->size : 0; + Value *v = alloc(sizeof(Value) + size); v->type = ArrayValue; - memcpy(v->data(), a, a->size); + memcpy(v->data(), a, size); return v; } diff --git a/tests/auto/tst_qtbinaryjson.cpp b/tests/auto/tst_qtbinaryjson.cpp index dd7950b..040d84e 100644 --- a/tests/auto/tst_qtbinaryjson.cpp +++ b/tests/auto/tst_qtbinaryjson.cpp @@ -63,6 +63,7 @@ private Q_SLOTS: void testValueArray(); void testObjectNested(); void testArrayNested(); + void testArrayNestedEmpty(); void nullValues(); void nullArrays(); @@ -304,6 +305,16 @@ void TestQtBinaryJson::testArrayNested() QCOMPARE(outer.last().toArray().last().toArray().at(0).toString(), QString("nested")); } +void TestQtBinaryJson::testArrayNestedEmpty() +{ + JsonObject object; + JsonArray inner; + object.insert("inner", inner); + JsonArray value = object.value("inner").toArray(); + QCOMPARE(value, inner); + QCOMPARE(value.size(), 0); +} + void TestQtBinaryJson::nullValues() { JsonArray array; |