Sorry I didn't investigate well on this problem before posting the question. It turned out that the qrcode received from the plc device is invalid. It contains only \0 while claiming length is 1. The problem is reproduced and fixed by checking c-style string end in the qrcode.
Thanks all who looked at the problem.