diff --git a/src/fd.cpp b/src/fd.cpp index 8f3fe13..f856c68 100644 --- a/src/fd.cpp +++ b/src/fd.cpp @@ -5,6 +5,7 @@ #include "main.hpp" +#include #include #include #include @@ -200,7 +201,7 @@ static int get_key_material_raw(const char * whom, bool again, bool newkey, uint auto bytes = getline((char **)&buf, &buflen, stdin); switch(bytes) { case -1: - if(errno != 0) + if(errno) TRY("read in passphrase", bytes); else // EOF bytes = 0; @@ -269,10 +270,9 @@ int read_new_passphrase(const char * whom, uint8_t *& buf, size_t & len_out, siz if(second_passphrase_len != first_passphrase_len || memcmp(first_passphrase, second_passphrase, first_passphrase_len)) return fprintf(stderr, "Provided keys do not match.\n"), __LINE__; - if(second_passphrase_len) { - buf = second_passphrase; - second_passphrase = nullptr; - } else + if(second_passphrase_len) + buf = std::exchange(second_passphrase, nullptr); + else buf = nullptr; len_out = second_passphrase_len; diff --git a/src/fd.hpp b/src/fd.hpp index d803b14..03b4b14 100644 --- a/src/fd.hpp +++ b/src/fd.hpp @@ -16,6 +16,7 @@ int with_stdin_at(int fd, F && what) { TRY("dup2() onto stdin", dup2(fd, 0)); + clearerr(stdin); if(int ret = what()) { dup2(stdin_saved, 0); return ret;