Address problems reported by John O'Brien in 228353. My changes differ
from the patch included with that bug report, mostly by being more
general and hopefully head off some bikeshed discussions.
PR: 228353
Submitted by: John W. O'Brien <john@saltant.com>