fix uninitialised memory access
fix buffer overrun