From: Niki Roo Date: Fri, 5 Jul 2024 18:58:51 +0000 (+0200) Subject: fix potential crash X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=16693f8d7e63374fb5999bbd98e4c5b98041e962;p=nsub.git fix potential crash --- diff --git a/src/nsub/nsub_read_lrc.c b/src/nsub/nsub_read_lrc.c index 01d4120..7e56a25 100644 --- a/src/nsub/nsub_read_lrc.c +++ b/src/nsub/nsub_read_lrc.c @@ -55,9 +55,9 @@ int nsub_read_lrc(song_t *song, char *line) { { lyric_t *lyric = array_last(song->lyrics); - if (lyric->type == NSUB_LYRIC) + if (lyric && lyric->type == NSUB_LYRIC) lyric->stop = start; - if (lyric->type == NSUB_COMMENT) + if (lyric && lyric->type == NSUB_COMMENT) name = lyric->text; // Comments starting with "[" (or "-- [") should not be names diff --git a/src/nsub/nsub_read_srt.c b/src/nsub/nsub_read_srt.c index daf486b..c19bc9f 100644 --- a/src/nsub/nsub_read_srt.c +++ b/src/nsub/nsub_read_srt.c @@ -41,10 +41,7 @@ int nsub_read_srt(song_t *song, char *line) { return 1; size_t count = array_count(song->lyrics); - lyric_t *lyric = NULL; - if (count) - lyric = array_get(song->lyrics, array_count(song->lyrics) - 1); - + lyric_t *lyric = array_last(song->lyrics); if (is_srt_id(line)) { int new_count = atoi(line); if (new_count != count + 1) { diff --git a/src/nsub/nsub_read_webvtt.c b/src/nsub/nsub_read_webvtt.c index c57708e..99a5afe 100644 --- a/src/nsub/nsub_read_webvtt.c +++ b/src/nsub/nsub_read_webvtt.c @@ -41,10 +41,7 @@ int nsub_read_webvtt(song_t *song, char *line) { return 1; size_t count = array_count(song->lyrics); - lyric_t *lyric = NULL; - if (count) - lyric = array_get(song->lyrics, array_count(song->lyrics) - 1); - + lyric_t *lyric = array_last(song->lyrics); if (is_srt_id(line)) { int new_count = atoi(line); if (new_count != count + 1) {