Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From 1adc34da2e3f7d3a5c8cb600d5d62cd018f7ca65 Mon Sep 17 00:00:00 2001
From: Ryan Curtin <ryan@ratml.org>
Date: Sun, 9 Aug 2020 21:46:05 -0400
Subject: [PATCH 1/3] Fix handling of NULL pointers.
---
src/mlpack/core/cereal/pointer_wrapper.hpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/mlpack/core/cereal/pointer_wrapper.hpp b/src/mlpack/core/cereal/pointer_wrapper.hpp
index 3b3f228d6..36a657940 100644
--- a/src/mlpack/core/cereal/pointer_wrapper.hpp
+++ b/src/mlpack/core/cereal/pointer_wrapper.hpp
@@ -49,7 +49,9 @@ class pointer_wrapper
template<class Archive>
void save(Archive& ar, const unsigned int /*version*/) const
{
- std::unique_ptr<T> smartPointer = std::make_unique<T>(*this->localPointer);
+ std::unique_ptr<T> smartPointer;
+ if (this->localPointer != NULL)
+ smartPointer = std::make_unique<T>(std::move(*this->localPointer));
ar(CEREAL_NVP(smartPointer));
localPointer = smartPointer.release();
}
--
2.28.0.rc1
@shrit

This comment has been minimized.

Copy link

@shrit shrit commented Aug 12, 2020

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.