From 85fc49612816dcfc81c9dc265b146b0b90b0f184 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 8 Nov 2017 15:58:25 +0100 Subject: Prevent crashes when profiling translation bindings The m_v4Function member can now be a nullptr, which means we cannot use it as ID and we cannot retrieve the source location from it. Change-Id: Ibb49a3e68cf961f9ffe2a83b2a0b83f7d04e149e Reviewed-by: hjk Reviewed-by: Simon Hausmann --- src/qml/debugger/qqmlprofiler_p.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/qml/debugger') diff --git a/src/qml/debugger/qqmlprofiler_p.h b/src/qml/debugger/qqmlprofiler_p.h index 88f8e94f25..6dc9859295 100644 --- a/src/qml/debugger/qqmlprofiler_p.h +++ b/src/qml/debugger/qqmlprofiler_p.h @@ -237,14 +237,19 @@ public: // Add 1 to the ID, to make it different from the IDs the V4 profiler produces. The +1 makes // the pointer point into the middle of the QV4::Function. Thus it still points to valid // memory but we cannot accidentally create a duplicate key from another object. - quintptr locationId(id(function) + 1); + // If there is no function, use a static but valid address: The profiler itself. + quintptr locationId = function ? id(function) + 1 : id(this); m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), (1 << RangeStart | 1 << RangeLocation), Binding, locationId)); RefLocation &location = m_locations[locationId]; - if (!location.isValid()) - location = RefLocation(function); + if (!location.isValid()) { + if (function) + location = RefLocation(function); + else // Make it valid without actually providing a location + location.locationType = Binding; + } } // Have toByteArrays() construct another RangeData event from the same QString later. -- cgit v1.2.3