diff --git a/src/osgPlugins/md2/ReaderWriterMD2.cpp b/src/osgPlugins/md2/ReaderWriterMD2.cpp index f2dc98909..7d4f4fb2d 100644 --- a/src/osgPlugins/md2/ReaderWriterMD2.cpp +++ b/src/osgPlugins/md2/ReaderWriterMD2.cpp @@ -172,8 +172,6 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) return NULL; } - memset(mapbase, 0, st.st_size+1); - if (read(file_fd, mapbase, st.st_size) != st.st_size) { close (file_fd); @@ -181,6 +179,9 @@ load_md2 (const char *filename, const osgDB::ReaderWriter::Options* options) return NULL; } + // set the last value in the mapbase to 0 to make sure the buffer is null terminated for later string reads from it + ((char*)mapbase)[st.st_size] = 0; + if (g_md2NormalsArray == NULL) { g_md2NormalsArray = new osg::Vec3Array; for (int i = 0; i < NUMVERTEXNORMALS; i++)