From d3bb5aba467194c4a08637e8730208177f138780 Mon Sep 17 00:00:00 2001 From: Adrian Cohea Date: Sat, 18 Mar 2017 17:23:34 -0600 Subject: [PATCH] Addresses -Wdeprecated-declarations warnings changing all references of std::auto_ptr to std::unique_ptr and changing the implementation of get_directory_contents() to use readdir, which is now reentrant, instead of readdir_r. Signed-off-by: Andrew Ayer Note: old implementations or readdir might not be re-entrant, but that's OK because git-crypt is not multi-threaded. --- crypto-openssl-10.cpp | 8 ++++---- crypto.hpp | 4 ++-- util-unix.cpp | 34 ++++++++++------------------------ 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/crypto-openssl-10.cpp b/crypto-openssl-10.cpp index 8cb10f7..f0f2c53 100644 --- a/crypto-openssl-10.cpp +++ b/crypto-openssl-10.cpp @@ -63,8 +63,8 @@ Aes_ecb_encryptor::Aes_ecb_encryptor (const unsigned char* raw_key) Aes_ecb_encryptor::~Aes_ecb_encryptor () { - // Note: Explicit destructor necessary because class contains an auto_ptr - // which contains an incomplete type when the auto_ptr is declared. + // Note: Explicit destructor necessary because class contains an unique_ptr + // which contains an incomplete type when the unique_ptr is declared. explicit_memset(&impl->key, '\0', sizeof(impl->key)); } @@ -86,8 +86,8 @@ Hmac_sha1_state::Hmac_sha1_state (const unsigned char* key, size_t key_len) Hmac_sha1_state::~Hmac_sha1_state () { - // Note: Explicit destructor necessary because class contains an auto_ptr - // which contains an incomplete type when the auto_ptr is declared. + // Note: Explicit destructor necessary because class contains an unique_ptr + // which contains an incomplete type when the unique_ptr is declared. HMAC_cleanup(&(impl->ctx)); } diff --git a/crypto.hpp b/crypto.hpp index db03241..a7d7edb 100644 --- a/crypto.hpp +++ b/crypto.hpp @@ -57,7 +57,7 @@ public: private: struct Aes_impl; - std::auto_ptr impl; + std::unique_ptr impl; public: Aes_ecb_encryptor (const unsigned char* key); @@ -102,7 +102,7 @@ public: private: struct Hmac_impl; - std::auto_ptr impl; + std::unique_ptr impl; public: Hmac_sha1_state (const unsigned char* key, size_t key_len); diff --git a/util-unix.cpp b/util-unix.cpp index 6bea324..75ba924 100644 --- a/util-unix.cpp +++ b/util-unix.cpp @@ -179,19 +179,6 @@ int util_rename (const char* from, const char* to) return rename(from, to); } -static size_t sizeof_dirent_for (DIR* p) -{ - long name_max = fpathconf(dirfd(p), _PC_NAME_MAX); - if (name_max == -1) { - #ifdef NAME_MAX - name_max = NAME_MAX; - #else - name_max = 255; - #endif - } - return offsetof(struct dirent, d_name) + name_max + 1; // final +1 is for d_name's null terminator -} - std::vector get_directory_contents (const char* path) { std::vector contents; @@ -201,19 +188,18 @@ std::vector get_directory_contents (const char* path) throw System_error("opendir", path, errno); } try { - std::vector buffer(sizeof_dirent_for(dir)); - struct dirent* dirent_buffer = reinterpret_cast(&buffer[0]); struct dirent* ent = NULL; - int err = 0; - while ((err = readdir_r(dir, dirent_buffer, &ent)) == 0 && ent != NULL) { - if (std::strcmp(ent->d_name, ".") == 0 || std::strcmp(ent->d_name, "..") == 0) { - continue; - } - contents.push_back(ent->d_name); - } - if (err != 0) { - throw System_error("readdir_r", path, errno); + + errno = 0; + + while((ent = readdir(dir)) != NULL && errno == 0) { + if (std::strcmp(ent->d_name, ".") && std::strcmp(ent->d_name, "..")) + contents.push_back(ent->d_name); } + + if(errno) + throw System_error("readdir", path, errno); + } catch (...) { closedir(dir); throw;