From kde-commits Thu Sep 13 10:09:28 2018 From: Harald Sitter Date: Thu, 13 Sep 2018 10:09:28 +0000 To: kde-commits Subject: [kio-extras] sftp: [sftp] replace memset(0) hack with c++ initialization Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=153683337921055 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 = #define KIO_SFTP_SPECIAL_TIMEOUT 30 -#define ZERO_STRUCTP(x) do { if ((x) !=3D NULL) memset((char *)(x), 0, siz= eof(*(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_soc= ket, const QByteArray &app_ qCDebug(KIO_SFTP_LOG) << "debug =3D " << getenv("KIO_SFTP_LOG_VERBOSITY"= ); #endif = - mCallbacks =3D (ssh_callbacks) malloc(sizeof(struct ssh_callbacks_struct= )); + // Members are 'value initialized' to zero because of non-user defined (= )! + mCallbacks =3D new struct ssh_callbacks_struct(); if (mCallbacks =3D=3D nullptr) { error(KIO::ERR_OUT_OF_MEMORY, i18n("Could not allocate callbacks")); return; } - ZERO_STRUCTP(mCallbacks); = mCallbacks->userdata =3D this; mCallbacks->auth_function =3D ::auth_callback;