From 7f361b9877e7448d509e8b2d0220c8e0e0c6bcb1 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 21 Apr 2017 22:35:37 +0200 Subject: [PATCH] audiod: Avoid reading garbage in get_time_string(). 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/audiod.c b/audiod.c index db69cf14..32b6895d 100644 --- 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; -- 2.30.2