HomeFreeBSD

man: reset OPTIND before parsing args

Description

man: reset OPTIND before parsing args

From jilles: POSIX requires that a script set OPTIND=1 before using
different sets of parameters with getopts, or the results will be
unspecified.

The specific problem observed here is that we would execute man -f or
man -k without cleaning up state from man_parse_args()' getopts
loop. FreeBSD's /bin/sh seems to reset OPTIND to 1 after we hit the
second getopts loop, rendering the following shift harmless; other
/bin/sh implementations will leave it at what we came into the loop at
(e.g., bash as /bin/sh), shifting off any keywords that we had.

Input from: jilles
Reviewed by: allanjude, bapt, imp
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D32063

Details

Provenance
kevansAuthored on Sep 22 2021, 7:58 PM
Reviewer
allanjude
Differential Revision
D32063: man: reset OPTIND after parsing args
Parents
rGef50d5fbc39f: x86: Add NUMA nodes into CPU topology.
Branches
Unknown
Tags
Unknown