From 8bf5d8c571a34bffc4ae754087f40c1f1f9ebf46 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Thu, 23 Feb 2023 16:13:54 +0100 Subject: [PATCH] Fail gracefully when a unknown stream is found --- src/emu/emu.c | 16 ++++++++++++++-- src/emu/system.c | 10 ++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/emu/emu.c b/src/emu/emu.c index 73841d7..c51a03f 100644 --- a/src/emu/emu.c +++ b/src/emu/emu.c @@ -92,15 +92,24 @@ emu_connect(struct emu *emu) return 0; } -static void +static int set_current(struct emu *emu) { emu->ev = player_ev(&emu->player); emu->stream = player_stream(&emu->player); struct lpt *lpt = system_get_lpt(emu->stream); + if (lpt == NULL) { + /* For now die if we have a unknown stream */ + err("event from unknown stream: %s", + emu->stream->path); + return -1; + } + emu->loom = lpt->loom; emu->proc = lpt->proc; emu->thread = lpt->thread; + + return 0; } static void @@ -145,7 +154,10 @@ emu_step(struct emu *emu) return -1; } - set_current(emu); + if (set_current(emu) != 0) { + err("cannot set current event information"); + return -1; + } dbg("----- mvc=%s dclock=%ld -----", emu->ev->mcv, emu->ev->dclock); diff --git a/src/emu/system.c b/src/emu/system.c index 7c44ca2..106aac4 100644 --- a/src/emu/system.c +++ b/src/emu/system.c @@ -413,10 +413,9 @@ init_offsets(struct system *sys, struct trace *trace) for (struct stream *s = trace->streams; s; s = s->next) { struct lpt *lpt = system_get_lpt(s); - if (lpt == NULL) { - err("cannot get stream lpt"); - return -1; - } + /* Not LPT stream */ + if (lpt == NULL) + continue; int64_t offset = lpt->loom->clock_offset; if (stream_clkoff_set(s, offset) != 0) { @@ -478,6 +477,9 @@ system_get_lpt(struct stream *stream) { struct lpt *lpt = stream_data_get(stream); + if (lpt == NULL) + return NULL; + if (lpt->stream != stream) die("inconsistent stream in lpt map");