Welcome to little lamb

Code » qmdoc » commit 8567606

Properly handle when there's only the index

author Olivier Brunel
2023-07-07 16:13:32 UTC
committer Olivier Brunel
2023-07-07 16:59:36 UTC
parent 9b5115efb7aa91113004119793e3ec2e6969e783

Properly handle when there's only the index

It would generate the index, then try to do it again and fail due to bad
file descriptor, since it'd been closed already.

src/qmdoc/qmdoc.c +8 -2

diff --git a/src/qmdoc/qmdoc.c b/src/qmdoc/qmdoc.c
index 40ebc0a..9ff6b2a 100644
--- a/src/qmdoc/qmdoc.c
+++ b/src/qmdoc/qmdoc.c
@@ -2392,7 +2392,9 @@ main (int argc, const char *argv[])
         if (dirfd != AT_FDCWD) fd_close(dirfd);
     }
 
-    int i = 1;
+    /* usually start at 1, but if there's only one entry it means there's only
+     * the index, which means start with it. */
+    int i = NB_ENTRIES(&ctx) > 1;
     ctx.cur_grp_idx = 0;
     for (;;) {
         int cur_entry = genalloc_s(int, &ctx.ga_idx)[i];
@@ -2426,7 +2428,11 @@ main (int argc, const char *argv[])
         }
 
         if (++i == genalloc_len(int, &ctx.ga_idx)) {
-            if (!(ctx.doc.flags & DOC_FULL_TOC))
+            /* having DOC_FULL_TOC means this is the index, *but* this might be
+             * from the first time/loop around, in the odd case of there is only
+             * the index.
+             * This is why we also break if i==1 */
+            if (!(ctx.doc.flags & DOC_FULL_TOC) || i == 1)
                 break;
             i = 0;
             ctx.cur_grp_idx = 0;