sink-input, source-output: add a couple of assertions
authorTanu Kaskinen <tanuk@iki.fi>
Sun, 29 Oct 2017 19:15:48 +0000 (21:15 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Mon, 30 Oct 2017 14:46:15 +0000 (16:46 +0200)
Coverity complained about data->sink being possibly NULL when it's
dereferenced later. It was difficult for me to figure out whether that
was a false positive or not. Hopefully the comments make it a bit
easier to reason about the code in the future.

CID: 1323591

src/pulsecore/sink-input.c
src/pulsecore/source-output.c

index 05fe2c026c693f695da597ccbe707afff7fb1ee5..f993322e9acc2dbc975a9d39b0f5c311b349e415 100644 (file)
@@ -338,6 +338,11 @@ int pa_sink_input_new(
         data->format = pa_format_info_copy(pa_idxset_first(data->nego_formats, NULL));
 
     if (PA_LIKELY(data->format)) {
+        /* We know that data->sink is set, because data->format has been set.
+         * data->format is set after a successful format negotiation, and that
+         * can't happen before data->sink has been set. */
+        pa_assert(data->sink);
+
         pa_log_debug("Negotiated format: %s", pa_format_info_snprint(fmt, sizeof(fmt), data->format));
     } else {
         pa_format_info *format;
index f8a421aa81c6580f2228d1f2312de5063a680741..f8f4e0ef0068e0e45a1145ada111bc44e4e76191 100644 (file)
@@ -280,6 +280,11 @@ int pa_source_output_new(
         data->format = pa_format_info_copy(pa_idxset_first(data->nego_formats, NULL));
 
     if (PA_LIKELY(data->format)) {
+        /* We know that data->source is set, because data->format has been set.
+         * data->format is set after a successful format negotiation, and that
+         * can't happen before data->source has been set. */
+        pa_assert(data->source);
+
         pa_log_debug("Negotiated format: %s", pa_format_info_snprint(fmt, sizeof(fmt), data->format));
     } else {
         pa_format_info *format;