Prevent adding undefined array entries to CMap.map in mapRangeToArray (issue 4875)

Tentative patch to fix #4875.

I'm not sure if this is the correct/optimal way to fix the issue, which is the reason that I didn't bother including a test file yet. Also I didn't want to waste time running the botio tests until I knew if this patch is any good (note however that it *does* pass all tests locally).