瀏覽代碼

index_list() and index_list_desc() always return a list, even if empty.

default 3 年之前
父節點
當前提交
e2789cece5
共有 1 個文件被更改,包括 2 次插入4 次删除
  1. 2 4
      data.c

+ 2 - 4
data.c

@@ -485,7 +485,7 @@ int index_len(const char *fn)
 xs_list *index_list(const char *fn, int max)
 xs_list *index_list(const char *fn, int max)
 /* returns an index as a list */
 /* returns an index as a list */
 {
 {
-    xs_list *list = NULL;
+    xs_list *list = xs_list_new();
     FILE *f;
     FILE *f;
     int n = 0;
     int n = 0;
 
 
@@ -493,7 +493,6 @@ xs_list *index_list(const char *fn, int max)
         flock(fileno(f), LOCK_SH);
         flock(fileno(f), LOCK_SH);
 
 
         char line[256];
         char line[256];
-        list = xs_list_new();
 
 
         while (n < max && fgets(line, sizeof(line), f) != NULL) {
         while (n < max && fgets(line, sizeof(line), f) != NULL) {
             if (line[0] != '-') {
             if (line[0] != '-') {
@@ -513,7 +512,7 @@ xs_list *index_list(const char *fn, int max)
 xs_list *index_list_desc(const char *fn, int skip, int show)
 xs_list *index_list_desc(const char *fn, int skip, int show)
 /* returns an index as a list, in reverse order */
 /* returns an index as a list, in reverse order */
 {
 {
-    xs_list *list = NULL;
+    xs_list *list = xs_list_new();
     FILE *f;
     FILE *f;
     int n = 0;
     int n = 0;
 
 
@@ -521,7 +520,6 @@ xs_list *index_list_desc(const char *fn, int skip, int show)
         flock(fileno(f), LOCK_SH);
         flock(fileno(f), LOCK_SH);
 
 
         char line[256];
         char line[256];
-        list = xs_list_new();
 
 
         /* move to the end minus one entry (or more, if skipping entries) */
         /* move to the end minus one entry (or more, if skipping entries) */
         if (!fseek(f, 0, SEEK_END) && !fseek(f, (skip + 1) * -33, SEEK_CUR)) {
         if (!fseek(f, 0, SEEK_END) && !fseek(f, (skip + 1) * -33, SEEK_CUR)) {