=================================================================== RCS file: /cvs/mandoc/mansearch.c,v retrieving revision 1.73 retrieving revision 1.74 diff -u -p -r1.73 -r1.74 --- mandoc/mansearch.c 2017/05/17 21:19:32 1.73 +++ mandoc/mansearch.c 2017/07/01 09:47:30 1.74 @@ -1,4 +1,4 @@ -/* $OpenBSD: mansearch.c,v 1.73 2017/05/17 21:19:32 schwarze Exp $ */ +/* $OpenBSD: mansearch.c,v 1.74 2017/07/01 09:47:30 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons * Copyright (c) 2013-2017 Ingo Schwarze @@ -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; } /*