]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
audiod: Avoid reading garbage in get_time_string().
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 21 Apr 2017 20:35:37 +0000 (22:35 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 21 Apr 2017 20:58:10 +0000 (22:58 +0200)
If no writer is active, wstime is not initialized. Yet we check
whether wstime.tv_sec == 0.

Introduce a helper variable to avoid reading garbage. This also
improves readability.

Found by the clang static analyzer.

audiod.c

index db69cf141a3833a5227c12ccba3f81a9e357e3b3..32b6895dcf0da9393538e649f7241878b89e96c0 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -318,6 +318,7 @@ char *get_time_string(void)
                rskip; /* receiver start - sss */
        int slot_num = get_play_time_slot_num();
        struct slot_info *s = slot_num < 0? NULL : &slot[slot_num];
+       bool writer_active = s && s->wns && s->wns[0].btrn;
        char *msg;
 
        if (audiod_status == AUDIOD_OFF)
@@ -331,11 +332,11 @@ char *get_time_string(void)
        }
        /*
         * Valid status items and playing, set length and tmp to the stream
-        * start. We use the slot info and fall back to the info from current
-        * status items if no slot info is available.
+        * start. We use the writer start time from the slot info and fall back
+        * to the info from current status items if no writer is active yet.
         */
        tmp = &stat_task->server_stream_start;
-       if (s && s->wns && s->wns[0].btrn) { /* writer active in this slot */
+       if (writer_active) {
                btr_get_node_start(s->wns[0].btrn, &wstime);
                if (wstime.tv_sec != 0) { /* writer wrote something */
                        if (s->server_stream_start.tv_sec == 0) {
@@ -352,7 +353,7 @@ char *get_time_string(void)
                tv_diff(tmp, &stat_task->sa_time_diff, &sss);
        else
                tv_add(tmp, &stat_task->sa_time_diff, &sss);
-       if (!s || !s->wns || !s->wns[0].btrn || wstime.tv_sec == 0) {
+       if (!writer_active) {
                struct timeval diff;
                tv_diff(now, &sss, &diff);
                seconds = diff.tv_sec + stat_task->offset_seconds;