Fix navigating from last to previous image over invalid files

This commit is contained in:
Bert Münnich 2017-10-26 22:20:39 +02:00
parent 2d34c4b9bf
commit 64b885b6a9
2 changed files with 5 additions and 4 deletions

View File

@ -1,4 +1,4 @@
VERSION = git-20171024 VERSION = git-20171026
srcdir = . srcdir = .
VPATH = $(srcdir) VPATH = $(srcdir)

7
main.c
View File

@ -159,8 +159,8 @@ void remove_file(int n, bool manual)
memmove(files + n, files + n + 1, (filecnt - n - 1) * sizeof(*files)); memmove(files + n, files + n + 1, (filecnt - n - 1) * sizeof(*files));
} }
filecnt--; filecnt--;
if (fileidx >= filecnt) if (n < fileidx)
fileidx = filecnt - 1; fileidx--;
if (n < alternate) if (n < alternate)
alternate--; alternate--;
} }
@ -290,6 +290,7 @@ end:
void load_image(int new) void load_image(int new)
{ {
bool prev = new < fileidx;
static int current; static int current;
if (new < 0 || new >= filecnt) if (new < 0 || new >= filecnt)
@ -307,7 +308,7 @@ void load_image(int new)
remove_file(new, false); remove_file(new, false);
if (new >= filecnt) if (new >= filecnt)
new = filecnt - 1; new = filecnt - 1;
else if (new > 0 && new < fileidx) else if (new > 0 && prev)
new--; new--;
} }
files[new].flags &= ~FF_WARN; files[new].flags &= ~FF_WARN;