summaryrefslogtreecommitdiffstats
path: root/mansearch.c
diff options
context:
space:
mode:
Diffstat (limited to 'mansearch.c')
-rw-r--r--mansearch.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/mansearch.c b/mansearch.c
index 26a7c23f..ddfe2f5d 100644
--- a/mansearch.c
+++ b/mansearch.c
@@ -104,7 +104,8 @@ mansearch(const struct mansearch *search,
}
cur = maxres = 0;
- *res = NULL;
+ if (res != NULL)
+ *res = NULL;
outkey = KEY_Nd;
if (search->outkey != NULL)
@@ -173,6 +174,10 @@ mansearch(const struct mansearch *search,
lstmatch(search->arch, page->arch) == 0)
continue;
+ if (res == NULL) {
+ cur = 1;
+ break;
+ }
if (cur + 1 > maxres) {
maxres += 1024;
*res = mandoc_reallocarray(*res,
@@ -204,12 +209,13 @@ mansearch(const struct mansearch *search,
if (cur && search->firstmatch)
break;
}
- qsort(*res, cur, sizeof(struct manpage), manpage_compare);
+ if (res != NULL)
+ qsort(*res, cur, sizeof(struct manpage), manpage_compare);
if (chdir_status && getcwd_status && chdir(buf) == -1)
warn("%s", buf);
exprfree(e);
*sz = cur;
- return 1;
+ return res != NULL || cur;
}
/*