]> git.decadent.org.uk Git - nfs-utils.git/commit
text-based mount command: fix return value from po_rightmost()
authorChuck Lever <chuck.lever@oracle.com>
Tue, 17 Feb 2009 20:19:58 +0000 (15:19 -0500)
committerSteve Dickson <steved@redhat.com>
Tue, 17 Feb 2009 20:19:58 +0000 (15:19 -0500)
commite7ec5e745e851ad10c56d579463ee7e1b85c9c21
tree3861e6709ca92988397eebade67844604cddaff5
parent1f0a104ff4aa07141d59cfd1d78157e8ddf7e4ed
text-based mount command: fix return value from po_rightmost()

Recently commit 0dcb83a8 changed the po_rightmost() function to
distinguish among several possible mount options by taking a table
containing the alternatives, and returning the table index of the
entry which is rightmost in the mount option string.

If it didn't find any mount option that matches an entry from the
passed-in table, it returned zero.  This was the same behavior it had
before, when it only checked for two options at a time.  It returned
PO_NEITHER_FOUND, which was zero.

Since this is C, however, zero also happens to be a valid index into
the passed-in array of options.

Modify the po_rightmost() function to return -1 if the entry wasn't
found, and fix up the callers to look for a C-style array index that
starts at zero.

Thanks to Steve Dickson for troubleshooting the problem.  His solution
was merely to bump the return value, as callers already expected an
ordinal index instead of a C-style index.

I prefer this equivalent but slightly more extensive change because it
makes the behavior of po_rightmost() more closely match how humans
understand C arrays to work.  Let's address some of the confusion that
caused this bug, as well as fixing the run-time behavior.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
utils/mount/network.c
utils/mount/parse_opt.c
utils/mount/parse_opt.h
utils/mount/stropts.c