Fix build with MSVC 2013

Also add an assert hinted by MSVC code analysis tool.

No functional change.