]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Explicitely convert local buffers to a string before returning it
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 10 Apr 2019 10:24:49 +0000 (12:24 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 10 Apr 2019 12:26:49 +0000 (14:26 +0200)
That makes cppcheck happier, because otherwise it complains that
we return a local variable.

pdns/iputils.hh
pdns/misc.cc

index 498e03c9243df8334ce40ccec24e0741320387f9..6454c342cfbf51f28e9ccf0ea6df61668d6185fe 100644 (file)
@@ -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));
   }
index 08c42251cf70df8aeb2dd10c4d6cf7ddf96048b4..9b6eea36d56b2668367ed46974fb98a7b58805e5 100644 (file)
@@ -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);
 }