Fix mishandling of incomplete, inverted masks.
Merge pull request #4933 from nnethercote/fix-4926-masking

Fix mishandling of incomplete, inverted masks.