Use new (std::nothrow) throughout
If code uses "normal" `new`, the compiler is allowed to assume that
`nullptr` is never returned, even if built with -fno-exceptions.
Use `new (std::nothrow)` throughout so that `nullptr` gets returned
and can (in some cases) be handled.
Bug: 215451239
Test: VtsAidlKeyMintTargetTest
Ignore-AOSP-First: Cherry pick from AOSP
Change-Id: Ied97ce946c0fbfbd5449c533e7ce1acbd0f595c5
(cherry picked from commit b80ef359b047a6bb72947b582102a979568f5c30)
diff --git a/ng/AndroidKeyMintDevice.cpp b/ng/AndroidKeyMintDevice.cpp
index 9d2cc69..25ad463 100644
--- a/ng/AndroidKeyMintDevice.cpp
+++ b/ng/AndroidKeyMintDevice.cpp
@@ -213,9 +213,9 @@
constexpr size_t kOperationTableSize = 16;
AndroidKeyMintDevice::AndroidKeyMintDevice(SecurityLevel securityLevel)
- : impl_(new ::keymaster::AndroidKeymaster(
- [&]() -> auto {
- auto context = new PureSoftKeymasterContext(
+ : impl_(new (std::nothrow)::keymaster::AndroidKeymaster(
+ [&]() -> auto{
+ auto context = new (std::nothrow) PureSoftKeymasterContext(
KmVersion::KEYMINT_2, static_cast<keymaster_security_level_t>(securityLevel));
context->SetSystemVersion(::keymaster::GetOsVersion(),
::keymaster::GetOsPatchlevel());