Fix and test for ticket #4964 - assert in debug mode on x64