Skip to content

Commit

Permalink
pipeline::fetch: Do not pass a temporary to boost::any_cast
Browse files Browse the repository at this point in the history
boost::any_cast<T>(const any<T> &) coerces the payload to be const,
which is invalid if the wrapped object was not originally const.

This happens e.g. when boost::any contains an int which is wrapped in a
boost::any::holder<int>;
boost::any_cast<int>(const any<int> &) will try to coerce this into a
boost::any::holder<const int>
which results in undefined behavior.
  • Loading branch information
Mortal authored and svendcs committed Feb 18, 2015
1 parent 9c733f5 commit 814efe2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tpie/pipelining/pipeline.h
Expand Up @@ -181,7 +181,8 @@ class pipeline {

template <typename T>
T fetch(std::string key) {
return boost::any_cast<T>(fetch_any(key));
boost::any a = fetch_any(key);
return *boost::any_cast<T>(&a);
}

void forward_any(std::string key, const boost::any & value) {
Expand Down

0 comments on commit 814efe2

Please sign in to comment.