=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.218 retrieving revision 1.220 diff -u -p -r1.218 -r1.220 --- mandoc/main.c 2015/02/03 21:16:02 1.218 +++ mandoc/main.c 2015/02/10 08:05:30 1.220 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.218 2015/02/03 21:16:02 schwarze Exp $ */ +/* $Id: main.c,v 1.220 2015/02/10 08:05:30 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -134,8 +134,9 @@ main(int argc, char *argv[]) int options; int c; - progname = strrchr(argv[0], '/'); - if (progname == NULL) + if (argc < 1) + progname = "mandoc"; + else if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; else ++progname; @@ -287,8 +288,10 @@ main(int argc, char *argv[]) /* Parse arguments. */ - argc -= optind; - argv += optind; + if (argc > 0) { + argc -= optind; + argv += optind; + } resp = NULL; /* @@ -414,13 +417,13 @@ main(int argc, char *argv[]) if (OUTT_MAN == curp.outtype) mparse_keep(curp.mp); - if (argc == 0) { + if (argc < 1) { if (use_pager && isatty(STDOUT_FILENO)) spawn_pager(); parse(&curp, STDIN_FILENO, "", &rc); } - while (argc) { + while (argc > 0) { rctmp = mparse_open(curp.mp, &fd, resp != NULL ? resp->file : *argv); if (rc < rctmp) @@ -563,7 +566,7 @@ found: " consider running # makewhatis %s\n", progname, name, sec, paths->paths[ipath]); #endif - + *res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage)); page = *res + (*ressz - 1); page->file = file;