From 6d99d6dd05c63f2d16073b6e4b3b30ebe02c8e5f Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 25 Sep 2008 20:27:48 +0000 Subject: [PATCH] imprved fix for mantis 312 --- src/ca/hostNameCache.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ca/hostNameCache.cpp b/src/ca/hostNameCache.cpp index 9522678ac..baaca7f66 100644 --- a/src/ca/hostNameCache.cpp +++ b/src/ca/hostNameCache.cpp @@ -22,10 +22,10 @@ * johill@lanl.gov */ +#include +#include + #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" - -#include - #include "hostNameCache.h" #include "epicsGuard.h" @@ -56,10 +56,11 @@ void hostNameCache::transactionComplete ( const char * pHostNameIn ) // set the entrire string to nill terminators before we start copying // in the name (this reduces the chance that another thread will see // garbage characters). + size_t newNameLen = std :: min < size_t > ( + strlen ( pHostNameIn ), sizeof ( this->hostNameBuf ) - 1u ); strncpy ( this->hostNameBuf, "", sizeof ( this->hostNameBuf ) ); strncpy ( this->hostNameBuf, pHostNameIn, sizeof ( this->hostNameBuf ) - 1 ); - this->hostNameBuf[ sizeof ( this->hostNameBuf ) - 1 ] = '\0'; - this->nameLength = strlen ( this->hostNameBuf ); + this->nameLength = newNameLen; } unsigned hostNameCache::getName (