[devel] [PATCH for apt 08/38] Use 'explicit' keyword for constructors with one argument

Aleksei Nikiforov darktemplar на altlinux.org
Вт Дек 10 18:23:13 MSK 2019


Disable copying of classes which allocate a memory buffer.
Found via cppcheck.
---
 apt/cmdline/apt-shell.cc   | 4 ++--
 apt/methods/ftp.h          | 2 +-
 apt/methods/http.h         | 5 ++++-
 apt/methods/rsh.h          | 2 +-
 apt/methods/rsync-method.h | 5 ++++-
 5 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/apt/cmdline/apt-shell.cc b/apt/cmdline/apt-shell.cc
index 7b033da..36fa223 100644
--- a/apt/cmdline/apt-shell.cc
+++ b/apt/cmdline/apt-shell.cc
@@ -94,7 +94,7 @@ class AutoRestore
    inline pkgDepCache::State *operator ->() {return &State;};
    inline pkgDepCache::State *operator &() {return &State;};
    inline void UnGuard() { Guarded = false; };
-   AutoRestore(pkgDepCache &Cache)
+   explicit AutoRestore(pkgDepCache &Cache)
       : State(&Cache), Guarded(true) {};
    ~AutoRestore() { if (Guarded) State.Restore(); };
 };
@@ -105,7 +105,7 @@ class AutoReOpenCache
    bool Guarded;
    public:
    inline void UnGuard() { Guarded = false; };
-   AutoReOpenCache(CacheFile *&Cache)
+   explicit AutoReOpenCache(CacheFile *&Cache)
       : Cache(&Cache), Guarded(true) {};
    ~AutoReOpenCache()
    {
diff --git a/apt/methods/ftp.h b/apt/methods/ftp.h
index 1535fff..b4a30fe 100644
--- a/apt/methods/ftp.h
+++ b/apt/methods/ftp.h
@@ -59,7 +59,7 @@ class FTPConn
    bool Get(const char *Path,FileFd &To,unsigned long long Resume,
 	    Hashes &MD5,bool &Missing);
    
-   FTPConn(URI Srv);
+   explicit FTPConn(URI Srv);
    ~FTPConn();
 };
 
diff --git a/apt/methods/http.h b/apt/methods/http.h
index 3b50e73..642a813 100644
--- a/apt/methods/http.h
+++ b/apt/methods/http.h
@@ -73,8 +73,11 @@ class CircleBuf
    void Reset();
    void Stats();
 
-   CircleBuf(unsigned long Size);
+   explicit CircleBuf(unsigned long Size);
    ~CircleBuf() {delete [] Buf; delete Hash;};
+
+   CircleBuf(const CircleBuf &other) = delete;
+   CircleBuf& operator=(const CircleBuf &other) = delete;
 };
 
 struct ServerState
diff --git a/apt/methods/rsh.h b/apt/methods/rsh.h
index 97c70bb..e99c59c 100644
--- a/apt/methods/rsh.h
+++ b/apt/methods/rsh.h
@@ -45,7 +45,7 @@ class RSHConn
    bool Get(const char *Path,FileFd &To,unsigned long long Resume,
             Hashes &Hash,bool &Missing, unsigned long long Size);
 
-   RSHConn(URI Srv);
+   explicit RSHConn(URI Srv);
    ~RSHConn();
 };
 
diff --git a/apt/methods/rsync-method.h b/apt/methods/rsync-method.h
index 1a30a39..356b4e8 100644
--- a/apt/methods/rsync-method.h
+++ b/apt/methods/rsync-method.h
@@ -20,9 +20,12 @@ class Argv
    char **args;
 
   public:
-   Argv(int msize);
+   explicit Argv(int msize);
    ~Argv();
 
+   Argv(const Argv &other) = delete;
+   Argv& operator=(const Argv &other) = delete;
+
    bool add(const char *arg);
    bool add(const string &arg) { return add( arg.c_str()); }
    bool resize();
-- 
2.24.0



Подробная информация о списке рассылки Devel