=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.123 retrieving revision 1.124 diff -u -r1.123 -r1.124 --- src/usr.bin/mandoc/main.c 2015/01/20 21:12:46 1.123 +++ src/usr.bin/mandoc/main.c 2015/02/07 06:27:53 1.124 @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.123 2015/01/20 21:12:46 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.124 2015/02/07 06:27:53 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -125,8 +125,9 @@ 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; @@ -277,8 +278,10 @@ /* Parse arguments. */ - argc -= optind; - argv += optind; + if (argc > 0) { + argc -= optind; + argv += optind; + } resp = NULL; /* @@ -395,13 +398,13 @@ 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)