From 1fa3355b80d8d421a1d37433d05958698ea3b222 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Thu, 11 Jan 2024 07:37:48 -0800 Subject: Don't use std::allocator::pointer It's removed in C++20 Bug: 175635923 Test: m MODULES-IN-external-libbrillo Change-Id: I23e6609991f759089fe40bcf181cbee9687cfc59 --- brillo/secure_allocator.h | 11 +++++------ brillo/secure_blob_test.cc | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/brillo/secure_allocator.h b/brillo/secure_allocator.h index de0b348..ad0036b 100644 --- a/brillo/secure_allocator.h +++ b/brillo/secure_allocator.h @@ -53,7 +53,6 @@ namespace brillo { template class BRILLO_PRIVATE SecureAllocator : public std::allocator { public: - using typename std::allocator::pointer; using typename std::allocator::size_type; using typename std::allocator::value_type; @@ -75,8 +74,8 @@ class BRILLO_PRIVATE SecureAllocator : public std::allocator { size_type max_size() const { return max_size_; } // Allocation: allocate ceil(size/pagesize) for holding the data. - pointer allocate(size_type n, pointer hint = nullptr) { - pointer buffer = nullptr; + value_type* allocate(size_type n, value_type* hint = nullptr) { + value_type* buffer = nullptr; // Check if n can be theoretically allocated. CHECK_LT(n, max_size()); @@ -97,7 +96,7 @@ class BRILLO_PRIVATE SecureAllocator : public std::allocator { size_type buffer_size = CalculatePageAlignedBufferSize(n); // Memory locking granularity is per-page: mmap ceil(size/page size) pages. - buffer = reinterpret_cast( + buffer = reinterpret_cast( mmap(nullptr, buffer_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); if (buffer == MAP_FAILED) @@ -155,7 +154,7 @@ class BRILLO_PRIVATE SecureAllocator : public std::allocator { clear_contents(p, sizeof(U)); } - virtual void deallocate(pointer p, size_type n) { + virtual void deallocate(value_type* p, size_type n) { // Check if n can be theoretically deallocated. CHECK_LT(n, max_size()); @@ -182,7 +181,7 @@ class BRILLO_PRIVATE SecureAllocator : public std::allocator { #endif // Zero-out all bytes in the allocated buffer. - virtual void __attribute_no_opt clear_contents(pointer v, size_type n) { + virtual void __attribute_no_opt clear_contents(value_type* v, size_type n) { if (!v) return; memset(v, 0, n); diff --git a/brillo/secure_blob_test.cc b/brillo/secure_blob_test.cc index 871c79c..8a4a1e8 100644 --- a/brillo/secure_blob_test.cc +++ b/brillo/secure_blob_test.cc @@ -232,14 +232,13 @@ TEST_F(SecureBlobTest, HexStringToSecureBlob) { template class TestSecureAllocator : public SecureAllocator { public: - using typename SecureAllocator::pointer; using typename SecureAllocator::size_type; using typename SecureAllocator::value_type; int GetErasedCount() { return erased_count; } protected: - void clear_contents(pointer p, size_type n) override { + void clear_contents(value_type* p, size_type n) override { SecureAllocator::clear_contents(p, n); unsigned char *v = reinterpret_cast(p); for (int i = 0; i < n; i++) { -- cgit v1.2.3