Skip to content

Commit d3bb5ab

Browse files
Adrian CoheaAGWA
authored andcommitted
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 <agwa@andrewayer.name> Note: old implementations or readdir might not be re-entrant, but that's OK because git-crypt is not multi-threaded.
1 parent edfa3dc commit d3bb5ab

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

crypto-openssl-10.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ Aes_ecb_encryptor::Aes_ecb_encryptor (const unsigned char* raw_key)
6363

6464
Aes_ecb_encryptor::~Aes_ecb_encryptor ()
6565
{
66-
// Note: Explicit destructor necessary because class contains an auto_ptr
67-
// which contains an incomplete type when the auto_ptr is declared.
66+
// Note: Explicit destructor necessary because class contains an unique_ptr
67+
// which contains an incomplete type when the unique_ptr is declared.
6868

6969
explicit_memset(&impl->key, '\0', sizeof(impl->key));
7070
}
@@ -86,8 +86,8 @@ Hmac_sha1_state::Hmac_sha1_state (const unsigned char* key, size_t key_len)
8686

8787
Hmac_sha1_state::~Hmac_sha1_state ()
8888
{
89-
// Note: Explicit destructor necessary because class contains an auto_ptr
90-
// which contains an incomplete type when the auto_ptr is declared.
89+
// Note: Explicit destructor necessary because class contains an unique_ptr
90+
// which contains an incomplete type when the unique_ptr is declared.
9191

9292
HMAC_cleanup(&(impl->ctx));
9393
}

crypto.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Aes_ecb_encryptor {
5757
private:
5858
struct Aes_impl;
5959

60-
std::auto_ptr<Aes_impl> impl;
60+
std::unique_ptr<Aes_impl> impl;
6161

6262
public:
6363
Aes_ecb_encryptor (const unsigned char* key);
@@ -102,7 +102,7 @@ class Hmac_sha1_state {
102102
private:
103103
struct Hmac_impl;
104104

105-
std::auto_ptr<Hmac_impl> impl;
105+
std::unique_ptr<Hmac_impl> impl;
106106

107107
public:
108108
Hmac_sha1_state (const unsigned char* key, size_t key_len);

util-unix.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,6 @@ int util_rename (const char* from, const char* to)
179179
return rename(from, to);
180180
}
181181

182-
static size_t sizeof_dirent_for (DIR* p)
183-
{
184-
long name_max = fpathconf(dirfd(p), _PC_NAME_MAX);
185-
if (name_max == -1) {
186-
#ifdef NAME_MAX
187-
name_max = NAME_MAX;
188-
#else
189-
name_max = 255;
190-
#endif
191-
}
192-
return offsetof(struct dirent, d_name) + name_max + 1; // final +1 is for d_name's null terminator
193-
}
194-
195182
std::vector<std::string> get_directory_contents (const char* path)
196183
{
197184
std::vector<std::string> contents;
@@ -201,19 +188,18 @@ std::vector<std::string> get_directory_contents (const char* path)
201188
throw System_error("opendir", path, errno);
202189
}
203190
try {
204-
std::vector<unsigned char> buffer(sizeof_dirent_for(dir));
205-
struct dirent* dirent_buffer = reinterpret_cast<struct dirent*>(&buffer[0]);
206191
struct dirent* ent = NULL;
207-
int err = 0;
208-
while ((err = readdir_r(dir, dirent_buffer, &ent)) == 0 && ent != NULL) {
209-
if (std::strcmp(ent->d_name, ".") == 0 || std::strcmp(ent->d_name, "..") == 0) {
210-
continue;
211-
}
212-
contents.push_back(ent->d_name);
213-
}
214-
if (err != 0) {
215-
throw System_error("readdir_r", path, errno);
192+
193+
errno = 0;
194+
195+
while((ent = readdir(dir)) != NULL && errno == 0) {
196+
if (std::strcmp(ent->d_name, ".") && std::strcmp(ent->d_name, ".."))
197+
contents.push_back(ent->d_name);
216198
}
199+
200+
if(errno)
201+
throw System_error("readdir", path, errno);
202+
217203
} catch (...) {
218204
closedir(dir);
219205
throw;

0 commit comments

Comments
 (0)