Thanks for the bug report. I fixed the code so that it matches the documentation by installing the attached patches into Emacs master. The first patch is the fix, the second is merely refactoring.