Fix an out of bounds write error. Some more protection when reading in data and finally fix a few type casts warnings.

git-svn-id: http://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3828 ed541006-0bf7-43e9-8c4d-6fc63c346d47