trace: fix out-of-bound memory access