From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Tue, 10 Dec 2019 18:23:13 +0300 Message-Id: <20191210152343.33867-9-darktemplar@altlinux.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210152343.33867-1-darktemplar@altlinux.org> References: <20191210152343.33867-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Aleksei Nikiforov Subject: [devel] [PATCH for apt 08/38] Use 'explicit' keyword for constructors with one argument X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Dec 2019 15:24:42 -0000 Archived-At: List-Archive: List-Post: 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