fix potential crash
authorNiki Roo <niki@nikiroo.be>
Fri, 5 Jul 2024 18:58:51 +0000 (20:58 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 5 Jul 2024 18:58:51 +0000 (20:58 +0200)
src/nsub/nsub_read_lrc.c
src/nsub/nsub_read_srt.c
src/nsub/nsub_read_webvtt.c

index 01d41201c3d20488112c4c541b67fd51443bb2fa..7e56a259d9bcd3b9ce71f0b36bfc0bae4ebae832 100644 (file)
@@ -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
index daf486bd5bab6fd894e956d462a19803897df671..c19bc9f91d4fad31137435fc6d975b43aaf8b91c 100644 (file)
@@ -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) {
index c57708e4ad8236c12e80db7597a4272352593d99..99a5afe2380cc38705ee873e8caf96739794adc5 100644 (file)
@@ -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) {