Skip to content

Commit

Permalink
Use a callable type for ScopedFILE in settings_writer.cc
Browse files Browse the repository at this point in the history
Newer glibc have an attribute((nonnull(1))) on fclose. Attributes aren't
part of the language, so decltype(fclose) lose the attribute. It seems
this causes std::unique_ptr<FILE, decltype(fclose)> to trip
-Wignored-attributes in GCC.

This is a bit aggressive of a warning, but work around this with a
custom deleter, which makes the unique_ptr object smaller anyway.
(Though the compiler can, I hope, dissolve all of this anyway.)

Fixed: 642
Change-Id: I9a0206a8c5675f856e80c5266c90be42d66a5606
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62465
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
(cherry picked from commit e4f60679caa293c047be69f57fc48b46c7452327)
  • Loading branch information
davidben authored and skmcgrail committed Jan 22, 2024
1 parent 69263d8 commit 2aac0d9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crypto/test/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ bssl::UniquePtr<X509> CertFromPEM(const char *pem);
// unique_ptr will automatically call fclose on the file descriptior when the
// variable goes out of scope, so we need to specify BIO_NOCLOSE close flags
// to avoid a double-free condition.
struct fclose_deleter {
struct FileCloser {
void operator()(FILE *f) const { fclose(f); }
};

using TempFILE = std::unique_ptr<FILE, fclose_deleter>;
using TempFILE = std::unique_ptr<FILE, FileCloser>;

#endif // OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
4 changes: 2 additions & 2 deletions ssl/ssl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11951,11 +11951,11 @@ TEST(SSLTest, SSLFileTests) {
GTEST_SKIP();
#endif

struct fclose_deleter {
struct FileCloser {
void operator()(FILE *f) const { fclose(f); }
};

using ScopedFILE = std::unique_ptr<FILE, fclose_deleter>;
using ScopedFILE = std::unique_ptr<FILE, FileCloser>;

#if defined(OPENSSL_WINDOWS)
char rsa_pem_filename[L_tmpnam];
Expand Down
5 changes: 2 additions & 3 deletions ssl/test/settings_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ bool SettingsWriter::Commit() {
}
bssl::UniquePtr<uint8_t> free_settings(settings);

struct fclose_deleter {
struct FileCloser {
void operator()(FILE *f) const { fclose(f); }
};

using ScopedFILE = std::unique_ptr<FILE, fclose_deleter>;
using ScopedFILE = std::unique_ptr<FILE, FileCloser>;
ScopedFILE file(fopen(path_.c_str(), "w"));
if (!file) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions ssl/test/ssl_transfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ static bool WriteData(std::string prefix, const uint8_t *input, size_t len) {
return true;
}

struct fclose_deleter {
struct FileCloser {
void operator()(FILE *f) const { fclose(f); }
};

using ScopedFILE = std::unique_ptr<FILE, fclose_deleter>;
using ScopedFILE = std::unique_ptr<FILE, FileCloser>;
std::string path = prefix + "-" + std::to_string(rand());
ScopedFILE file(fopen(path.c_str(), "w"));
if (!file) {
Expand Down

0 comments on commit 2aac0d9

Please sign in to comment.