Fix substring operator in macro-processor.

The characters of the substring could be mixed with random characters from the
memory space. Thanks to Tom Holden for reporting the bug.

Closes #708

(cherry picked from commit 931ea41f187a452f3ad6a2355e552b6710fbd41e)