Fix invalid memory read (patch by Colomban Wendling, thanks).