Fix potential buffer overflow with temp sample space