From: Remi Gacogne Date: Wed, 10 Apr 2019 10:24:49 +0000 (+0200) Subject: Explicitely convert local buffers to a string before returning it X-Git-Tag: dnsdist-1.4.0-alpha1~2^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bfbf6814746c73723785c936d9a048ab1f1a155e;p=pdns Explicitely convert local buffers to a string before returning it That makes cppcheck happier, because otherwise it complains that we return a local variable. --- diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 498e03c92..6454c342c 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -278,7 +278,7 @@ union ComboAddress { char host[1024]; int retval = 0; if(sin4.sin_family && !(retval = getnameinfo((struct sockaddr*) this, getSocklen(), host, sizeof(host),0, 0, NI_NUMERICHOST))) - return host; + return string(host); else return "invalid "+string(gai_strerror(retval)); } diff --git a/pdns/misc.cc b/pdns/misc.cc index 08c42251c..9b6eea36d 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -202,7 +202,7 @@ string nowTime() // YYYY-mm-dd HH:MM:SS TZOFF strftime(buffer, sizeof(buffer), "%F %T %z", tm); buffer[sizeof(buffer)-1] = '\0'; - return buffer; + return string(buffer); } uint16_t getShort(const unsigned char *p) @@ -498,7 +498,7 @@ string getHostname() if(gethostname(tmp, MAXHOSTNAMELEN)) return "UNKNOWN"; - return tmp; + return string(tmp); } string itoa(int i) @@ -571,7 +571,7 @@ string U32ToIP(uint32_t val) (val >> 16)&0xff, (val >> 8)&0xff, (val )&0xff); - return tmp; + return string(tmp); }