From: APTX Date: Sat, 19 Feb 2022 09:20:44 +0000 (+0900) Subject: Use Q_CHECK_PTR to check all MPV pointers X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=6358bbd64782bcef42c5c829647ac2b20a6a21a9;p=aniplayer.git Use Q_CHECK_PTR to check all MPV pointers Removes all the "null deref" analyzer warnings. --- diff --git a/backendplugins/backend_mpv/backendmpv.cpp b/backendplugins/backend_mpv/backendmpv.cpp index 75b655b..2cd2289 100644 --- a/backendplugins/backend_mpv/backendmpv.cpp +++ b/backendplugins/backend_mpv/backendmpv.cpp @@ -202,8 +202,7 @@ template <> struct MpvProperty { template <> struct MpvProperty { static bool read(struct mpv_event_property *property) { Q_ASSERT(property->format == MPV_FORMAT_FLAG); - if (!property->data) - qWarning("Property data data is null"); + Q_CHECK_PTR(property->data); return *static_cast(property->data) ? true : false; } }; @@ -211,8 +210,7 @@ template <> struct MpvProperty { template <> struct MpvProperty { static qint64 read(struct mpv_event_property *property) { Q_ASSERT(property->format == MPV_FORMAT_INT64); - if (!property->data) - qWarning("Property data data is null"); + Q_CHECK_PTR(property->data); return *static_cast(property->data); } }; @@ -220,8 +218,7 @@ template <> struct MpvProperty { template <> struct MpvProperty { static double read(struct mpv_event_property *property) { Q_ASSERT(property->format == MPV_FORMAT_DOUBLE); - if (!property->data) - qWarning("Property data data is null"); + Q_CHECK_PTR(property->data); return *static_cast(property->data); } }; @@ -238,8 +235,7 @@ template <> struct MpvProperty { template <> struct MpvProperty { static char *read(struct mpv_event_property *property) { Q_ASSERT(property->format == MPV_FORMAT_STRING); - if (!property->data) - qWarning("Property data data is null"); + Q_CHECK_PTR(property->data); return *static_cast(property->data); } }; @@ -270,9 +266,9 @@ void MpvInstance::processMpvEvents() { << "), error: " << event->error; switch (event->event_id) { case MPV_EVENT_PROPERTY_CHANGE: { - if (!event->data) - qCWarning(mpvBackend, "PROPERTY CHANGE data is null"); + Q_CHECK_PTR(event->data); auto property = static_cast(event->data); + Q_CHECK_PTR(property); qCDebug(mpvVerboseBackend) << "Property" << property->name << "changed"; if (property->format == MPV_FORMAT_NONE) { qCDebug(mpvBackend) << "No data in event"; @@ -364,9 +360,9 @@ void MpvInstance::processMpvEvents() { } } break; case MPV_EVENT_LOG_MESSAGE: { - if (!event->data) - qCWarning(mpvBackend, "LOG MESSAGE data is null"); + Q_CHECK_PTR(event->data); auto log = static_cast(event->data); + Q_CHECK_PTR(log); QMessageLogger l{0, 0, 0, mpvLog().categoryName()}; if (log->log_level <= MPV_LOG_LEVEL_ERROR) l.critical() << log->text; @@ -391,8 +387,7 @@ void MpvInstance::processMpvEvents() { case MPV_EVENT_END_FILE: { m_loadedFile = false; - if (!event->data) - qCWarning(mpvBackend, "END FILE data is null"); + Q_CHECK_PTR(event->data); auto endFile = static_cast(event->data); if (endFile->reason == MPV_END_FILE_REASON_ERROR) qCWarning(mpvBackend).nospace()