[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kio-extras] sftp: [sftp] replace memset(0) hack with c++ initialization
From:       Harald Sitter <null () kde ! org>
Date:       2018-09-13 10:09:28
Message-ID: E1g0OYy-0005nW-1I () code ! kde ! org
[Download RAW message or body]

Git commit 0f92b54ca21a2c947a6e1ac365dbe9ec8aaec088 by Harald Sitter.
Committed on 13/09/2018 at 10:09.
Pushed by sitter into branch 'master'.

[sftp] replace memset(0) hack with c++ initialization

Summary:
new T() in c++11 in a class with a default constructor that is not user
provided will zero initialize the object.
(see docs on `value initialization`)

Reviewers: broulik

Reviewed By: broulik

Differential Revision: https://phabricator.kde.org/D15472

M  +2    -3    sftp/kio_sftp.cpp

https://commits.kde.org/kio-extras/0f92b54ca21a2c947a6e1ac365dbe9ec8aaec088

diff --git a/sftp/kio_sftp.cpp b/sftp/kio_sftp.cpp
index 0cd80df2..22530eb7 100644
--- a/sftp/kio_sftp.cpp
+++ b/sftp/kio_sftp.cpp
@@ -42,7 +42,6 @@
 #include <kio/ioslave_defaults.h>
 
 #define KIO_SFTP_SPECIAL_TIMEOUT 30
-#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
 
 // How big should each data packet be? Definitely not bigger than 64kb or
 // you will overflow the 2 byte size variable in a sftp packet.
@@ -453,12 +452,12 @@ sftpProtocol::sftpProtocol(const QByteArray &pool_socket, const QByteArray &app_
   qCDebug(KIO_SFTP_LOG) << "debug = " << getenv("KIO_SFTP_LOG_VERBOSITY");
 #endif
 
-  mCallbacks = (ssh_callbacks) malloc(sizeof(struct ssh_callbacks_struct));
+  // Members are 'value initialized' to zero because of non-user defined ()!
+  mCallbacks = new struct ssh_callbacks_struct();
   if (mCallbacks == nullptr) {
     error(KIO::ERR_OUT_OF_MEMORY, i18n("Could not allocate callbacks"));
     return;
   }
-  ZERO_STRUCTP(mCallbacks);
 
   mCallbacks->userdata = this;
   mCallbacks->auth_function = ::auth_callback;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic