Skip to content

Instantly share code, notes, and snippets.

@rcurtin
Created August 10, 2020 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcurtin/b55cf600d01f69e9e02556eeadefb35e to your computer and use it in GitHub Desktop.
Save rcurtin/b55cf600d01f69e9e02556eeadefb35e to your computer and use it in GitHub Desktop.
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
Copy link

shrit commented Aug 12, 2020

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment