From 55521747eec71aeb7a27b315a03135339622fc3e Mon Sep 17 00:00:00 2001 From: buslov Date: Thu, 16 Nov 2017 21:19:08 +0300 Subject: [PATCH] Fix V645 warning from PVS-Studio Static Analyzer The 'strncat' function call could lead to the 'metadata' buffer overflow. The bounds should not contain the size of the buffer, but a number of characters it can hold. --- src/population.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/population.cpp b/src/population.cpp index f4a5d6a..2146521 100644 --- a/src/population.cpp +++ b/src/population.cpp @@ -164,11 +164,11 @@ Population::Population(const char *filename) { { // If we've started to form the metadata, put a space in the front if(md) { - strncat(metadata, " ", 128 - strlen(metadata)); + strncat(metadata, " ", 128 - 1 - strlen(metadata)); } // Append the next word to the metadata, and say that there is metadata - strncat(metadata, curword, 128 - strlen(metadata)); + strncat(metadata, curword, 128 - 1 - strlen(metadata)); md = true; //strcpy(curword, NEAT::getUnit(curline, curwordnum++, delimiters));