aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-06-12 10:52:32 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2014-08-24 13:38:25 +0200
commitd41121119b97ed60e543eed4b8d308ad9d250682 (patch)
treeedd6c02af5622f3ba462f1d809da76ed7cf339c0
parenta400d33e812528ea463161c84591ac895d6b1879 (diff)
Don't abuse new to do a reinterpret_cast
Using new to do a reinterpret_cast is rather confusing. Also protect the list model case against self-assignment which could lead to memory corruption. Change-Id: I10b81644d0004d4a50a5a74e5b8c58e27cbe6934 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/types/qqmllistmodel.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp
index be49b6e5a0..f4c32cef1a 100644
--- a/src/qml/types/qqmllistmodel.cpp
+++ b/src/qml/types/qqmllistmodel.cpp
@@ -810,7 +810,7 @@ int ListElement::setDoubleProperty(const ListLayout::Role &role, double d)
if (role.type == ListLayout::Role::Number) {
char *mem = getPropertyMemory(role);
- double *value = new (mem) double;
+ double *value = reinterpret_cast<double *>(mem);
bool changed = *value != d;
*value = d;
if (changed)
@@ -826,7 +826,7 @@ int ListElement::setBoolProperty(const ListLayout::Role &role, bool b)
if (role.type == ListLayout::Role::Bool) {
char *mem = getPropertyMemory(role);
- bool *value = new (mem) bool;
+ bool *value = reinterpret_cast<bool *>(mem);
bool changed = *value != b;
*value = b;
if (changed)
@@ -842,8 +842,8 @@ int ListElement::setListProperty(const ListLayout::Role &role, ListModel *m)
if (role.type == ListLayout::Role::List) {
char *mem = getPropertyMemory(role);
- ListModel **value = new (mem) ListModel *;
- if (*value) {
+ ListModel **value = reinterpret_cast<ListModel **>(mem);
+ if (*value && *value != m) {
(*value)->destroy();
delete *value;
}