From 6fe75203a399b8cd0848ca9bda9d9aa4fdf3edd5 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 15 Jan 2018 11:22:39 +0100 Subject: QQmlProfilerService: Avoid type ambiguities Use C++ cast operators, and always choose types of defined length when interacting with the packet protocol. Also, don't let the client overflow the flush interval setting. Change-Id: I2f4654d4e3e350a979a989784dc61fbc8b97df2a Reviewed-by: Simon Hausmann --- .../qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp index c388c6e74a..0d69b2ab66 100644 --- a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp +++ b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp @@ -240,7 +240,7 @@ void QQmlProfilerServiceImpl::startProfiling(QJSEngine *engine, quint64 features QQmlDebugPacket d; - d << m_timer.nsecsElapsed() << (int)Event << (int)StartTrace; + d << m_timer.nsecsElapsed() << static_cast(Event) << static_cast(StartTrace); bool startedAny = false; if (engine != 0) { const auto range = qAsConst(m_engineProfilers).equal_range(engine); @@ -338,7 +338,8 @@ void QQmlProfilerServiceImpl::sendMessages() QQmlDebugPacket traceEnd; if (m_waitingForStop) { - traceEnd << m_timer.nsecsElapsed() << (int)Event << (int)EndTrace; + traceEnd << m_timer.nsecsElapsed() << static_cast(Event) + << static_cast(EndTrace); QSet seen; for (QQmlAbstractProfilerAdapter *profiler : qAsConst(m_startTimes)) { @@ -373,7 +374,7 @@ void QQmlProfilerServiceImpl::sendMessages() messages << traceEnd.data(); QQmlDebugPacket ds; - ds << (qint64)-1 << (int)Complete; + ds << static_cast(-1) << static_cast(Complete); messages << ds.data(); m_waitingForStop = false; } @@ -414,7 +415,7 @@ void QQmlProfilerServiceImpl::messageReceived(const QByteArray &message) int engineId = -1; quint64 features = std::numeric_limits::max(); bool enabled; - uint flushInterval = 0; + quint32 flushInterval = 0; stream >> enabled; if (!stream.atEnd()) stream >> engineId; @@ -422,7 +423,9 @@ void QQmlProfilerServiceImpl::messageReceived(const QByteArray &message) stream >> features; if (!stream.atEnd()) { stream >> flushInterval; - m_flushTimer.setInterval(flushInterval); + m_flushTimer.setInterval( + static_cast(qMin(flushInterval, + static_cast(std::numeric_limits::max())))); auto timerStart = static_cast(&QTimer::start); if (flushInterval > 0) { connect(&m_flushTimer, &QTimer::timeout, this, &QQmlProfilerServiceImpl::flush); -- cgit v1.2.3