Created attachment 6753 [details]
charmap that shows the bug
If a charmap doesn't define a mapping for at least one character in the range u+0001 to u+0006 then the translation table generated by gap.awk is broken. For example with the attached TEST charmap then u+0041 gets mapped to a \4a instead of \x41.
The bug happens because gap.awk sets "last" (the last codepoint output) to zero, instead of -1. A patch to gap.awk and gaptab.awk is attached.
Created attachment 6754 [details]
patch to gap.awk and gaptab.awk to fix bug