]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
clang-tidy: DynListener::getLine.
authorAxel Viala <axel.viala@darnuria.eu>
Fri, 2 Sep 2022 20:38:34 +0000 (22:38 +0200)
committerAxel Viala <axel.viala@darnuria.eu>
Wed, 26 Oct 2022 17:28:45 +0000 (19:28 +0200)
Fix founds with:

- [readability-implicit-bool-conversion]
  - pdns/dynlistener.cc:256
  - pdns/dynlistener.cc:272:8

- [readability-container-data-pointer]
  - pdns/dynlistener.cc:240:19
  - pdns/dynlistener.cc:245:25
  - pdns/dynlistener.cc:256:17
  - dns/dynlistener.cc:263:17

- [bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions]
  - pdns/dynlistener.cc:240:29
  - pdns/dynlistener.cc:256:27

Avoided to fix `if` related to avoid making too much noise.

pdns/dynlistener.cc

index 63d06bd36815a25e35c47b58c5c36ad7eff3e4d8..70a9270a6100ddff0844b56f9a5ab6958c7bbb30 100644 (file)
@@ -214,7 +214,7 @@ string DynListener::getLine()
   vector<char> mesg;
   mesg.resize(1024000);
 
-  ssize_t len;
+  ssize_t len = 0;
 
   ComboAddress remote;
   socklen_t remlen=remote.getSocklen();
@@ -237,12 +237,12 @@ string DynListener::getLine()
 
       std::shared_ptr<FILE> fp=std::shared_ptr<FILE>(fdopen(dup(d_client), "r"), fclose);
       if(d_tcp) {
-        if(!fgets(&mesg[0], mesg.size(), fp.get())) {
+        if (fgets(mesg.data(), static_cast<int>(mesg.size()), fp.get()) == nullptr) {
           g_log<<Logger::Error<<"Unable to receive password from controlsocket ("<<d_client<<"): "<<stringerror()<<endl;
           close(d_client);
           continue;
         }
-        string password(&mesg[0]);
+        string password(mesg.data());
         boost::trim(password);
         if(password.empty() || password!=arg()["tcp-control-secret"]) {
           g_log<<Logger::Error<<"Wrong password on TCP control socket"<<endl;
@@ -253,14 +253,15 @@ string DynListener::getLine()
         }
       }
       errno=0;
-      if(!fgets(&mesg[0], mesg.size(), fp.get())) {
-        if(errno)
+      if (fgets(mesg.data(), static_cast<int>(mesg.size()), fp.get()) == nullptr) {
+        if (errno) {
           g_log<<Logger::Error<<"Unable to receive line from controlsocket ("<<d_client<<"): "<<stringerror()<<endl;
+        }
         close(d_client);
         continue;
       }
       
-      if(strlen(&mesg[0]) == mesg.size()) {
+      if (strlen(mesg.data()) == mesg.size()) {
         g_log<<Logger::Error<<"Line on controlsocket ("<<d_client<<") was too long"<<endl;
         close(d_client);
         continue;
@@ -269,10 +270,10 @@ string DynListener::getLine()
     }
   }
   else {
-    if(isatty(0))
+    if(isatty(0) != 0)
       if(write(1, "% ", 2) !=2)
         throw PDNSException("Writing to console: "+stringerror());
-    if((len=read(0, &mesg[0], mesg.size())) < 0) 
+    if((len=read(0, mesg.data(), mesg.size())) < 0)
       throw PDNSException("Reading from the control pipe: "+stringerror());
     else if(len==0)
       throw PDNSException("Guardian exited - going down as well");
@@ -283,7 +284,7 @@ string DynListener::getLine()
     mesg[len]=0;
   }
 
-  return &mesg[0];
+  return mesg.data();
 }
 
 void DynListener::sendlines(const string &l)