Add a check for a NULL pointer, which stops fnext/fprev
from segfaulting if given an empty folder list (for example
via 'fnext -folders emptyfile').
Signed-off-by: Peter Maydell <pmaydell@chiark.greenend.org.uk>
folders, sequences);
if (run_mode == FNEXT || run_mode == FPREV) {
- if (first->n_next == NULL) {
+ if (first == NULL) {
+ /* No folders at all... */
+ return NULL;
+ } else if (first->n_next == NULL) {
/* We have only one node; any desired messages in it? */
if (first->n_field == NULL) {
return NULL;