validate: Cast GList data content before usage

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
This commit is contained in:
Edward Hervey 2017-07-19 11:02:44 +02:00 committed by Edward Hervey
parent 2177d8589c
commit 8b9b6ead3f
7 changed files with 59 additions and 50 deletions

View file

@ -72,8 +72,10 @@ gst_validate_bin_set_media_descriptor (GstValidateMonitor * monitor,
GST_VALIDATE_MONITOR_LOCK (monitor); GST_VALIDATE_MONITOR_LOCK (monitor);
for (tmp = GST_VALIDATE_BIN_MONITOR_CAST (monitor)->element_monitors; tmp; for (tmp = GST_VALIDATE_BIN_MONITOR_CAST (monitor)->element_monitors; tmp;
tmp = tmp->next) tmp = tmp->next) {
gst_validate_monitor_set_media_descriptor (tmp->data, media_descriptor); GstValidateMonitor *sub_monitor = (GstValidateMonitor *) tmp->data;
gst_validate_monitor_set_media_descriptor (sub_monitor, media_descriptor);
}
GST_VALIDATE_MONITOR_UNLOCK (monitor); GST_VALIDATE_MONITOR_UNLOCK (monitor);
GST_VALIDATE_MONITOR_CLASS (parent_class)->set_media_descriptor (monitor, GST_VALIDATE_MONITOR_CLASS (parent_class)->set_media_descriptor (monitor,

View file

@ -360,8 +360,9 @@ _load_text_override_file (const gchar * filename)
GList *tmp; GList *tmp;
for (tmp = structs; tmp; tmp = tmp->next) { for (tmp = structs; tmp; tmp = tmp->next) {
if (!_add_override_from_struct (tmp->data)) { GstStructure *_struct = (GstStructure *) tmp->data;
GST_ERROR ("Wrong overrides %" GST_PTR_FORMAT, tmp->data); if (!_add_override_from_struct (_struct)) {
GST_ERROR ("Wrong overrides %" GST_PTR_FORMAT, _struct);
ret = WRONG_OVERRIDES; ret = WRONG_OVERRIDES;
} }
} }

View file

@ -1763,7 +1763,7 @@ gst_validate_monitor_find_next_buffer (GstValidatePadMonitor * pad_monitor)
return; return;
for (tmp = g_list_last (pad_monitor->all_bufs); tmp; tmp = tmp->prev) { for (tmp = g_list_last (pad_monitor->all_bufs); tmp; tmp = tmp->prev) {
GstBuffer *cbuf = tmp->data; GstBuffer *cbuf = (GstBuffer *) tmp->data;
GstClockTime ts = GstClockTime ts =
GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cbuf)) ? GST_BUFFER_DTS (cbuf) GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cbuf)) ? GST_BUFFER_DTS (cbuf)
: GST_BUFFER_PTS (cbuf); : GST_BUFFER_PTS (cbuf);

View file

@ -221,9 +221,11 @@ _gather_pad_negotiation_details (GstPad * pad, GString * str,
next = GST_ELEMENT (gst_pad_get_parent (peer)); next = GST_ELEMENT (gst_pad_get_parent (peer));
GST_OBJECT_LOCK (next); GST_OBJECT_LOCK (next);
for (tmp = next->srcpads; tmp; tmp = tmp->next) for (tmp = next->srcpads; tmp; tmp = tmp->next) {
_gather_pad_negotiation_details (tmp->data, str, GstPad *to_check = (GstPad *) tmp->data;
_gather_pad_negotiation_details (to_check, str,
last_query_caps_fail_monitor, last_refused_caps_monitor); last_query_caps_fail_monitor, last_refused_caps_monitor);
}
GST_OBJECT_UNLOCK (next); GST_OBJECT_UNLOCK (next);
gst_object_unref (peer); gst_object_unref (peer);
@ -447,9 +449,11 @@ _generate_not_negotiated_error_report (GstMessage * msg)
GST_OBJECT_NAME (element)); GST_OBJECT_NAME (element));
GST_OBJECT_LOCK (element); GST_OBJECT_LOCK (element);
for (tmp = element->srcpads; tmp; tmp = tmp->next) for (tmp = element->srcpads; tmp; tmp = tmp->next) {
_gather_pad_negotiation_details (tmp->data, str, GstPad *to_check = (GstPad *) tmp->data;
_gather_pad_negotiation_details (to_check, str,
&last_query_caps_fail_monitor, &last_refused_caps_monitor); &last_query_caps_fail_monitor, &last_refused_caps_monitor);
}
GST_OBJECT_UNLOCK (element); GST_OBJECT_UNLOCK (element);
if (last_query_caps_fail_monitor) if (last_query_caps_fail_monitor)

View file

@ -682,8 +682,10 @@ gst_validate_runner_get_reports_count (GstValidateRunner * runner)
GST_VALIDATE_RUNNER_LOCK (runner); GST_VALIDATE_RUNNER_LOCK (runner);
l = g_list_length (runner->priv->reports); l = g_list_length (runner->priv->reports);
for (tmp = runner->priv->reports; tmp; tmp = tmp->next) for (tmp = runner->priv->reports; tmp; tmp = tmp->next) {
l += g_list_length (((GstValidateReport *) tmp->data)->repeated_reports); GstValidateReport *report = (GstValidateReport *) tmp->data;
l += g_list_length (report->repeated_reports);
}
l += g_hash_table_size (runner->priv->reports_by_type); l += g_hash_table_size (runner->priv->reports_by_type);
GST_VALIDATE_RUNNER_UNLOCK (runner); GST_VALIDATE_RUNNER_UNLOCK (runner);
@ -740,7 +742,7 @@ _do_report_synthesis (GstValidateRunner * runner)
} }
for (tmp = g_list_next (reports); tmp; tmp = tmp->next) { 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); gst_validate_report_print_detected_on (report);
if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) { if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) {
@ -780,22 +782,20 @@ gst_validate_runner_printf (GstValidateRunner * runner)
criticals = _do_report_synthesis (runner); criticals = _do_report_synthesis (runner);
reports = gst_validate_runner_get_reports (runner); reports = gst_validate_runner_get_reports (runner);
for (tmp = reports; tmp; tmp = tmp->next) { for (tmp = reports; tmp; tmp = tmp->next) {
GstValidateReport *report = tmp->data; GstValidateReport *report = (GstValidateReport *) tmp->data;
if (gst_validate_report_should_print (report)) if (gst_validate_report_should_print (report))
gst_validate_report_printf (report); gst_validate_report_printf (report);
if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) { if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) {
criticals = g_list_append (criticals, tmp->data); criticals = g_list_append (criticals, report);
} }
} }
if (criticals) { if (criticals) {
GList *iter; GList *iter;
g_printerr ("\n\n==== Got criticals. Return value set to 18 ====\n"); g_printerr ("\n\n==== Got criticals. Return value set to 18 ====\n");
ret = 18; ret = 18;
for (iter = criticals; iter; iter = iter->next) { for (iter = criticals; iter; iter = iter->next) {
g_printerr (" Critical error %s\n", g_printerr (" Critical error %s\n",
((GstValidateReport *) (iter->data))->message); ((GstValidateReport *) (iter->data))->message);
@ -814,19 +814,14 @@ int
gst_validate_runner_exit (GstValidateRunner * runner, gboolean print_result) gst_validate_runner_exit (GstValidateRunner * runner, gboolean print_result)
{ {
gint ret = 0; gint ret = 0;
g_return_val_if_fail (GST_IS_VALIDATE_RUNNER (runner), 1); g_return_val_if_fail (GST_IS_VALIDATE_RUNNER (runner), 1);
g_signal_emit (runner, _signals[STOPPING_SIGNAL], 0); g_signal_emit (runner, _signals[STOPPING_SIGNAL], 0);
if (print_result) { if (print_result) {
ret = gst_validate_runner_printf (runner); ret = gst_validate_runner_printf (runner);
} else { } else {
GList *tmp; GList *tmp;
for (tmp = runner->priv->reports; tmp; tmp = tmp->next) { 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) if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL)
ret = 18; ret = 18;
} }

View file

@ -181,8 +181,9 @@ gst_validate_scenario_intercept_report (GstValidateReporter * reporter,
for (tmp = GST_VALIDATE_SCENARIO (reporter)->priv->overrides; tmp; for (tmp = GST_VALIDATE_SCENARIO (reporter)->priv->overrides; tmp;
tmp = tmp->next) { tmp = tmp->next) {
GstValidateOverride *override = (GstValidateOverride *) tmp->data;
report->level = report->level =
gst_validate_override_get_severity (tmp->data, gst_validate_override_get_severity (override,
gst_validate_issue_get_id (report->issue), report->level); gst_validate_issue_get_id (report->issue), report->level);
} }
@ -422,8 +423,9 @@ _find_action_type (const gchar * type_name)
GList *tmp; GList *tmp;
for (tmp = action_types; tmp; tmp = tmp->next) { for (tmp = action_types; tmp; tmp = tmp->next) {
if (g_strcmp0 (((GstValidateActionType *) tmp->data)->name, type_name) == 0) GstValidateActionType *atype = (GstValidateActionType *) tmp->data;
return tmp->data; if (g_strcmp0 (atype->name, type_name) == 0)
return atype;
} }
return NULL; return NULL;
@ -1770,8 +1772,8 @@ _fill_action (GstValidateScenario * scenario, GstValidateAction * action,
GList *tmp; GList *tmp;
for (tmp = priv->actions; tmp; tmp = tmp->next) { for (tmp = priv->actions; tmp; tmp = tmp->next) {
if (GST_CLOCK_TIME_IS_VALID (((GstValidateAction *) tmp-> GstValidateAction *act = (GstValidateAction *) tmp->data;
data)->playback_time)) { if (GST_CLOCK_TIME_IS_VALID (act->playback_time)) {
can_execute_on_addition = FALSE; can_execute_on_addition = FALSE;
break; break;
} }
@ -2651,7 +2653,7 @@ message_cb (GstBus * bus, GstMessage * message, GstValidateScenario * scenario)
GList *tmp; GList *tmp;
for (tmp = priv->needs_parsing; tmp; tmp = tmp->next) { 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)) if (!_set_action_playback_time (scenario, action))
return FALSE; return FALSE;
@ -2725,7 +2727,7 @@ message_cb (GstBus * bus, GstMessage * message, GstValidateScenario * scenario)
for (tmp = all_actions; tmp; tmp = tmp->next) { for (tmp = all_actions; tmp; tmp = tmp->next) {
gchar *action_string; gchar *action_string;
GstValidateAction *action = ((GstValidateAction *) tmp->data); GstValidateAction *action = (GstValidateAction *) tmp->data;
GstValidateActionType *type = _find_action_type (action->type); GstValidateActionType *type = _find_action_type (action->type);
tmpconcat = actions; tmpconcat = actions;
@ -2881,8 +2883,7 @@ _load_scenario_file (GstValidateScenario * scenario,
GstValidateAction *action; GstValidateAction *action;
GstValidateActionType *action_type; GstValidateActionType *action_type;
const gchar *type; const gchar *type;
GstStructure *structure = (GstStructure *) tmp->data;
GstStructure *structure = tmp->data;
type = gst_structure_get_name (structure); 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); GList *tmp, *structures = gst_validate_structs_parse_from_gfile (f);
for (tmp = structures; tmp; tmp = tmp->next) { for (tmp = structures; tmp; tmp = tmp->next) {
GstStructure *_struct = (GstStructure *) tmp->data;
GstValidateActionType *type = 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")) if (!desc && gst_structure_has_name (_struct, "description"))
desc = gst_structure_copy (tmp->data); desc = gst_structure_copy (_struct);
else if (type && type->flags & GST_VALIDATE_ACTION_TYPE_NEEDS_CLOCK) else if (type && type->flags & GST_VALIDATE_ACTION_TYPE_NEEDS_CLOCK)
needs_clock_sync = TRUE; needs_clock_sync = TRUE;
} }
@ -3835,7 +3837,7 @@ gst_validate_print_action_types (const gchar ** wanted_types,
gint nfound = 0; gint nfound = 0;
for (tmp = gst_validate_list_action_types (); tmp; tmp = tmp->next) { for (tmp = gst_validate_list_action_types (); tmp; tmp = tmp->next) {
GstValidateActionType *atype = tmp->data; GstValidateActionType *atype = (GstValidateActionType *) tmp->data;
gboolean print = FALSE; gboolean print = FALSE;
if (num_wanted_types) { if (num_wanted_types) {
@ -3855,7 +3857,7 @@ gst_validate_print_action_types (const gchar ** wanted_types,
} }
if (print && num_wanted_types) { if (print && num_wanted_types) {
gst_validate_printf (tmp->data, "\n"); gst_validate_printf (atype, "\n");
} else if (print) { } else if (print) {
gchar *desc = gchar *desc =
g_regex_replace (newline_regex, atype->description, -1, 0, "\n ", 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) { for (tmp = gst_validate_plugin_get_config (NULL); tmp; tmp = tmp->next) {
const gchar *action_typename; 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; GstValidateAction *action;
GstValidateActionType *atype = _find_action_type (action_typename); GstValidateActionType *atype = _find_action_type (action_typename);
@ -4332,16 +4335,17 @@ init_scenarios (void)
if (!(atype->flags & GST_VALIDATE_ACTION_TYPE_CONFIG) && if (!(atype->flags & GST_VALIDATE_ACTION_TYPE_CONFIG) &&
!(_action_type_has_parameter (atype, "as-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; continue;
} }
gst_structure_set (tmp->data, "as-config", G_TYPE_BOOLEAN, TRUE, NULL); gst_structure_set (plug_conf, "as-config", G_TYPE_BOOLEAN, TRUE, NULL);
gst_structure_set_name (tmp->data, action_typename); gst_structure_set_name (plug_conf, action_typename);
action = gst_validate_action_new (NULL, tmp->data); action = gst_validate_action_new (NULL, atype);
_fill_action (NULL, action, tmp->data, FALSE); _fill_action (NULL, action, plug_conf, FALSE);
} }
} }
} }

View file

@ -344,9 +344,10 @@ _find_stream_id (GstPad * pad, GstEvent ** event,
gst_event_parse_stream_start (*event, &stream_id); gst_event_parse_stream_start (*event, &stream_id);
for (tmp = ((GstValidateMediaDescriptor *) writer)->filenode->streams; tmp; for (tmp = ((GstValidateMediaDescriptor *) writer)->filenode->streams; tmp;
tmp = tmp->next) { tmp = tmp->next) {
if (g_strcmp0 (((GstValidateMediaStreamNode *) GstValidateMediaStreamNode *subnode =
tmp->data)->id, stream_id) == 0) { (GstValidateMediaStreamNode *) tmp->data;
snode = tmp->data; if (g_strcmp0 (subnode->id, stream_id) == 0) {
snode = subnode;
break; break;
} }
@ -645,7 +646,9 @@ gst_validate_media_descriptor_writer_new_discover (GstValidateRunner * runner,
streams = gst_discoverer_info_get_stream_list (info); streams = gst_discoverer_info_get_stream_list (info);
for (tmp = streams; tmp; tmp = tmp->next) { 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 { } else {
gst_validate_media_descriptor_writer_add_stream (writer, streaminfo); 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; for (tmp = ((GstValidateMediaDescriptor *) writer)->filenode->streams; tmp;
tmp = tmp->next) { tmp = tmp->next) {
if (g_strcmp0 (( GstValidateMediaStreamNode *subnode =
(GstValidateMediaStreamNode (GstValidateMediaStreamNode *) tmp->data;
*) tmp->data)->id, stream_id) == 0) { if (g_strcmp0 (subnode->id, stream_id) == 0) {
snode = tmp->data; snode = subnode;
break; break;
} }