fix invalid memory access