From 6d65768dabe8ea1a115dc3767fb24401db0f8e39 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 3 Nov 2017 09:49:50 +0000 Subject: [PATCH] Added an explict null termination of buffer to address Coverity Scan reported issue --- src/osgPlugins/md2/ReaderWriterMD2.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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++)