Make the fix for bug 8999 actually work

This backports 1cdbb94f which was spotted by cppcheck.