]> Some of my projects - aniplayer.git/commitdiff
Use Q_CHECK_PTR to check all MPV pointers
authorAPTX <marek321@gmail.com>
Sat, 19 Feb 2022 09:20:44 +0000 (18:20 +0900)
committerAPTX <marek321@gmail.com>
Mon, 21 Feb 2022 15:10:20 +0000 (00:10 +0900)
Removes all the "null deref" analyzer warnings.

backendplugins/backend_mpv/backendmpv.cpp

index 75b655b312e3b9821e2ce0b37f160b29dd1ebf51..2cd2289e7dc52b192eebb82eb275df01c8f9d832 100644 (file)
@@ -202,8 +202,7 @@ template <> struct MpvProperty<MPV_FORMAT_NONE> {
 template <> struct MpvProperty<MPV_FORMAT_FLAG> {
   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<int *>(property->data) ? true : false;
   }
 };
@@ -211,8 +210,7 @@ template <> struct MpvProperty<MPV_FORMAT_FLAG> {
 template <> struct MpvProperty<MPV_FORMAT_INT64> {
   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<qint64 *>(property->data);
   }
 };
@@ -220,8 +218,7 @@ template <> struct MpvProperty<MPV_FORMAT_INT64> {
 template <> struct MpvProperty<MPV_FORMAT_DOUBLE> {
   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<double *>(property->data);
   }
 };
@@ -238,8 +235,7 @@ template <> struct MpvProperty<MPV_FORMAT_NODE> {
 template <> struct MpvProperty<MPV_FORMAT_STRING> {
   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<char **>(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<mpv_event_property *>(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<mpv_event_log_message *>(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<mpv_event_end_file *>(event->data);
       if (endFile->reason == MPV_END_FILE_REASON_ERROR)
         qCWarning(mpvBackend).nospace()