validate: Cast GList data content before usage
authorEdward Hervey <edward@centricular.com>
Wed, 19 Jul 2017 09:02:44 +0000 (11:02 +0200)
committerEdward Hervey <bilboed@bilboed.com>
Wed, 19 Jul 2017 09:02:44 +0000 (11:02 +0200)
Apart from code readability, it allows compilers to detect wrong usages,
such as the call to gst_validate_action_new() which was using the wrong
argument

validate/gst/validate/gst-validate-bin-monitor.c
validate/gst/validate/gst-validate-override-registry.c
validate/gst/validate/gst-validate-pad-monitor.c
validate/gst/validate/gst-validate-pipeline-monitor.c
validate/gst/validate/gst-validate-runner.c
validate/gst/validate/gst-validate-scenario.c
validate/gst/validate/media-descriptor-writer.c

index bb841ba..f57dff5 100644 (file)
@@ -72,8 +72,10 @@ gst_validate_bin_set_media_descriptor (GstValidateMonitor * monitor,
 
   GST_VALIDATE_MONITOR_LOCK (monitor);
   for (tmp = GST_VALIDATE_BIN_MONITOR_CAST (monitor)->element_monitors; tmp;
-      tmp = tmp->next)
-    gst_validate_monitor_set_media_descriptor (tmp->data, media_descriptor);
+      tmp = tmp->next) {
+    GstValidateMonitor *sub_monitor = (GstValidateMonitor *) tmp->data;
+    gst_validate_monitor_set_media_descriptor (sub_monitor, media_descriptor);
+  }
   GST_VALIDATE_MONITOR_UNLOCK (monitor);
 
   GST_VALIDATE_MONITOR_CLASS (parent_class)->set_media_descriptor (monitor,
index c2b157a..dabe209 100644 (file)
@@ -360,8 +360,9 @@ _load_text_override_file (const gchar * filename)
     GList *tmp;
 
     for (tmp = structs; tmp; tmp = tmp->next) {
-      if (!_add_override_from_struct (tmp->data)) {
-        GST_ERROR ("Wrong overrides %" GST_PTR_FORMAT, tmp->data);
+      GstStructure *_struct = (GstStructure *) tmp->data;
+      if (!_add_override_from_struct (_struct)) {
+        GST_ERROR ("Wrong overrides %" GST_PTR_FORMAT, _struct);
         ret = WRONG_OVERRIDES;
       }
     }
index 646946b..37aa3e5 100644 (file)
@@ -1763,7 +1763,7 @@ gst_validate_monitor_find_next_buffer (GstValidatePadMonitor * pad_monitor)
     return;
 
   for (tmp = g_list_last (pad_monitor->all_bufs); tmp; tmp = tmp->prev) {
-    GstBuffer *cbuf = tmp->data;
+    GstBuffer *cbuf = (GstBuffer *) tmp->data;
     GstClockTime ts =
         GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cbuf)) ? GST_BUFFER_DTS (cbuf)
         : GST_BUFFER_PTS (cbuf);
index 7bfffe8..7b413e4 100644 (file)
@@ -221,9 +221,11 @@ _gather_pad_negotiation_details (GstPad * pad, GString * str,
 
   next = GST_ELEMENT (gst_pad_get_parent (peer));
   GST_OBJECT_LOCK (next);
-  for (tmp = next->srcpads; tmp; tmp = tmp->next)
-    _gather_pad_negotiation_details (tmp->data, str,
+  for (tmp = next->srcpads; tmp; tmp = tmp->next) {
+    GstPad *to_check = (GstPad *) tmp->data;
+    _gather_pad_negotiation_details (to_check, str,
         last_query_caps_fail_monitor, last_refused_caps_monitor);
+  }
   GST_OBJECT_UNLOCK (next);
 
   gst_object_unref (peer);
@@ -447,9 +449,11 @@ _generate_not_negotiated_error_report (GstMessage * msg)
       GST_OBJECT_NAME (element));
 
   GST_OBJECT_LOCK (element);
-  for (tmp = element->srcpads; tmp; tmp = tmp->next)
-    _gather_pad_negotiation_details (tmp->data, str,
+  for (tmp = element->srcpads; tmp; tmp = tmp->next) {
+    GstPad *to_check = (GstPad *) tmp->data;
+    _gather_pad_negotiation_details (to_check, str,
         &last_query_caps_fail_monitor, &last_refused_caps_monitor);
+  }
   GST_OBJECT_UNLOCK (element);
 
   if (last_query_caps_fail_monitor)
index afa6be9..69dac55 100644 (file)
@@ -682,8 +682,10 @@ gst_validate_runner_get_reports_count (GstValidateRunner * runner)
 
   GST_VALIDATE_RUNNER_LOCK (runner);
   l = g_list_length (runner->priv->reports);
-  for (tmp = runner->priv->reports; tmp; tmp = tmp->next)
-    l += g_list_length (((GstValidateReport *) tmp->data)->repeated_reports);
+  for (tmp = runner->priv->reports; tmp; tmp = tmp->next) {
+    GstValidateReport *report = (GstValidateReport *) tmp->data;
+    l += g_list_length (report->repeated_reports);
+  }
   l += g_hash_table_size (runner->priv->reports_by_type);
   GST_VALIDATE_RUNNER_UNLOCK (runner);
 
@@ -740,7 +742,7 @@ _do_report_synthesis (GstValidateRunner * runner)
     }
 
     for (tmp = g_list_next (reports); tmp; tmp = tmp->next) {
-      report = (GstValidateReport *) (tmp->data);
+      report = (GstValidateReport *) tmp->data;
       gst_validate_report_print_detected_on (report);
 
       if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) {
@@ -780,22 +782,20 @@ gst_validate_runner_printf (GstValidateRunner * runner)
   criticals = _do_report_synthesis (runner);
   reports = gst_validate_runner_get_reports (runner);
   for (tmp = reports; tmp; tmp = tmp->next) {
-    GstValidateReport *report = tmp->data;
+    GstValidateReport *report = (GstValidateReport *) tmp->data;
 
     if (gst_validate_report_should_print (report))
       gst_validate_report_printf (report);
 
     if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) {
-      criticals = g_list_append (criticals, tmp->data);
+      criticals = g_list_append (criticals, report);
     }
   }
 
   if (criticals) {
     GList *iter;
-
     g_printerr ("\n\n==== Got criticals. Return value set to 18 ====\n");
     ret = 18;
-
     for (iter = criticals; iter; iter = iter->next) {
       g_printerr ("     Critical error %s\n",
           ((GstValidateReport *) (iter->data))->message);
@@ -814,19 +814,14 @@ int
 gst_validate_runner_exit (GstValidateRunner * runner, gboolean print_result)
 {
   gint ret = 0;
-
   g_return_val_if_fail (GST_IS_VALIDATE_RUNNER (runner), 1);
-
   g_signal_emit (runner, _signals[STOPPING_SIGNAL], 0);
-
   if (print_result) {
     ret = gst_validate_runner_printf (runner);
   } else {
     GList *tmp;
-
     for (tmp = runner->priv->reports; tmp; tmp = tmp->next) {
-      GstValidateReport *report = tmp->data;
-
+      GstValidateReport *report = (GstValidateReport *) tmp->data;
       if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL)
         ret = 18;
     }
index 4370912..5c521fe 100644 (file)
@@ -181,8 +181,9 @@ gst_validate_scenario_intercept_report (GstValidateReporter * reporter,
 
   for (tmp = GST_VALIDATE_SCENARIO (reporter)->priv->overrides; tmp;
       tmp = tmp->next) {
+    GstValidateOverride *override = (GstValidateOverride *) tmp->data;
     report->level =
-        gst_validate_override_get_severity (tmp->data,
+        gst_validate_override_get_severity (override,
         gst_validate_issue_get_id (report->issue), report->level);
   }
 
@@ -422,8 +423,9 @@ _find_action_type (const gchar * type_name)
   GList *tmp;
 
   for (tmp = action_types; tmp; tmp = tmp->next) {
-    if (g_strcmp0 (((GstValidateActionType *) tmp->data)->name, type_name) == 0)
-      return tmp->data;
+    GstValidateActionType *atype = (GstValidateActionType *) tmp->data;
+    if (g_strcmp0 (atype->name, type_name) == 0)
+      return atype;
   }
 
   return NULL;
@@ -1770,8 +1772,8 @@ _fill_action (GstValidateScenario * scenario, GstValidateAction * action,
       GList *tmp;
 
       for (tmp = priv->actions; tmp; tmp = tmp->next) {
-        if (GST_CLOCK_TIME_IS_VALID (((GstValidateAction *) tmp->
-                    data)->playback_time)) {
+        GstValidateAction *act = (GstValidateAction *) tmp->data;
+        if (GST_CLOCK_TIME_IS_VALID (act->playback_time)) {
           can_execute_on_addition = FALSE;
           break;
         }
@@ -2651,7 +2653,7 @@ message_cb (GstBus * bus, GstMessage * message, GstValidateScenario * scenario)
         GList *tmp;
 
         for (tmp = priv->needs_parsing; tmp; tmp = tmp->next) {
-          GstValidateAction *action = tmp->data;
+          GstValidateAction *action = (GstValidateAction *) tmp->data;
 
           if (!_set_action_playback_time (scenario, action))
             return FALSE;
@@ -2725,7 +2727,7 @@ message_cb (GstBus * bus, GstMessage * message, GstValidateScenario * scenario)
 
         for (tmp = all_actions; tmp; tmp = tmp->next) {
           gchar *action_string;
-          GstValidateAction *action = ((GstValidateAction *) tmp->data);
+          GstValidateAction *action = (GstValidateAction *) tmp->data;
           GstValidateActionType *type = _find_action_type (action->type);
 
           tmpconcat = actions;
@@ -2881,8 +2883,7 @@ _load_scenario_file (GstValidateScenario * scenario,
     GstValidateAction *action;
     GstValidateActionType *action_type;
     const gchar *type;
-
-    GstStructure *structure = tmp->data;
+    GstStructure *structure = (GstStructure *) tmp->data;
 
 
     type = gst_structure_get_name (structure);
@@ -3437,11 +3438,12 @@ _parse_scenario (GFile * f, GKeyFile * kf)
     GList *tmp, *structures = gst_validate_structs_parse_from_gfile (f);
 
     for (tmp = structures; tmp; tmp = tmp->next) {
+      GstStructure *_struct = (GstStructure *) tmp->data;
       GstValidateActionType *type =
-          _find_action_type (gst_structure_get_name (tmp->data));
+          _find_action_type (gst_structure_get_name (_struct));
 
-      if (!desc && gst_structure_has_name (tmp->data, "description"))
-        desc = gst_structure_copy (tmp->data);
+      if (!desc && gst_structure_has_name (_struct, "description"))
+        desc = gst_structure_copy (_struct);
       else if (type && type->flags & GST_VALIDATE_ACTION_TYPE_NEEDS_CLOCK)
         needs_clock_sync = TRUE;
     }
@@ -3835,7 +3837,7 @@ gst_validate_print_action_types (const gchar ** wanted_types,
   gint nfound = 0;
 
   for (tmp = gst_validate_list_action_types (); tmp; tmp = tmp->next) {
-    GstValidateActionType *atype = tmp->data;
+    GstValidateActionType *atype = (GstValidateActionType *) tmp->data;
     gboolean print = FALSE;
 
     if (num_wanted_types) {
@@ -3855,7 +3857,7 @@ gst_validate_print_action_types (const gchar ** wanted_types,
     }
 
     if (print && num_wanted_types) {
-      gst_validate_printf (tmp->data, "\n");
+      gst_validate_printf (atype, "\n");
     } else if (print) {
       gchar *desc =
           g_regex_replace (newline_regex, atype->description, -1, 0, "\n      ",
@@ -4319,8 +4321,9 @@ init_scenarios (void)
 
   for (tmp = gst_validate_plugin_get_config (NULL); tmp; tmp = tmp->next) {
     const gchar *action_typename;
+    GstStructure *plug_conf = (GstStructure *) tmp->data;
 
-    if ((action_typename = gst_structure_get_string (tmp->data, "action"))) {
+    if ((action_typename = gst_structure_get_string (plug_conf, "action"))) {
       GstValidateAction *action;
       GstValidateActionType *atype = _find_action_type (action_typename);
 
@@ -4332,16 +4335,17 @@ init_scenarios (void)
 
       if (!(atype->flags & GST_VALIDATE_ACTION_TYPE_CONFIG) &&
           !(_action_type_has_parameter (atype, "as-config"))) {
-        g_error ("[CONFIG ERROR] Action is not a config action");
+        g_error ("[CONFIG ERROR] Action '%s' is not a config action",
+            action_typename);
 
         continue;
       }
 
-      gst_structure_set (tmp->data, "as-config", G_TYPE_BOOLEAN, TRUE, NULL);
-      gst_structure_set_name (tmp->data, action_typename);
+      gst_structure_set (plug_conf, "as-config", G_TYPE_BOOLEAN, TRUE, NULL);
+      gst_structure_set_name (plug_conf, action_typename);
 
-      action = gst_validate_action_new (NULL, tmp->data);
-      _fill_action (NULL, action, tmp->data, FALSE);
+      action = gst_validate_action_new (NULL, atype);
+      _fill_action (NULL, action, plug_conf, FALSE);
     }
   }
 }
index 198b171..f666f5a 100644 (file)
@@ -344,9 +344,10 @@ _find_stream_id (GstPad * pad, GstEvent ** event,
     gst_event_parse_stream_start (*event, &stream_id);
     for (tmp = ((GstValidateMediaDescriptor *) writer)->filenode->streams; tmp;
         tmp = tmp->next) {
-      if (g_strcmp0 (((GstValidateMediaStreamNode *)
-                  tmp->data)->id, stream_id) == 0) {
-        snode = tmp->data;
+      GstValidateMediaStreamNode *subnode =
+          (GstValidateMediaStreamNode *) tmp->data;
+      if (g_strcmp0 (subnode->id, stream_id) == 0) {
+        snode = subnode;
 
         break;
       }
@@ -645,7 +646,9 @@ gst_validate_media_descriptor_writer_new_discover (GstValidateRunner * runner,
 
       streams = gst_discoverer_info_get_stream_list (info);
       for (tmp = streams; tmp; tmp = tmp->next) {
-        gst_validate_media_descriptor_writer_add_stream (writer, tmp->data);
+        GstDiscovererStreamInfo *streaminfo =
+            (GstDiscovererStreamInfo *) tmp->data;
+        gst_validate_media_descriptor_writer_add_stream (writer, streaminfo);
       }
     } else {
       gst_validate_media_descriptor_writer_add_stream (writer, streaminfo);
@@ -693,10 +696,10 @@ gst_validate_media_descriptor_writer_add_tags (GstValidateMediaDescriptorWriter
 
   for (tmp = ((GstValidateMediaDescriptor *) writer)->filenode->streams; tmp;
       tmp = tmp->next) {
-    if (g_strcmp0 ((
-                (GstValidateMediaStreamNode
-                    *) tmp->data)->id, stream_id) == 0) {
-      snode = tmp->data;
+    GstValidateMediaStreamNode *subnode =
+        (GstValidateMediaStreamNode *) tmp->data;
+    if (g_strcmp0 (subnode->id, stream_id) == 0) {
+      snode = subnode;
 
       break;
     }