Fix potential buffer overflow
problem spotted and fixed by WiseguyTom
Detailed explanation in #34
closes #34