From: Roman Donchenko Date: Wed, 4 Sep 2013 10:06:34 +0000 (+0400) Subject: Fixed a bug in FLANN resulting in uninitialized accesses. X-Git-Tag: accepted/tizen/ivi/20140515.103456~1^2~514^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a9975b144a22e76228125eb0a25f78ec13db6815;p=profile%2Fivi%2Fopencv.git Fixed a bug in FLANN resulting in uninitialized accesses. This is fixed upstream in mariusmuja/flann@b615f26, but that fix would break binary compatibility, so I had to make a different one. Since the bug isn't quite obvious, here's an explanation. In the const version of any::cast, if policy is a small_any_policy, its get_value returns its input argument. So r becomes a pointer to obj, and the return value is a reference to a local variable, which is invalidated when the function exits. --- diff --git a/modules/flann/include/opencv2/flann/any.h b/modules/flann/include/opencv2/flann/any.h index 89189c6..7140b2a 100644 --- a/modules/flann/include/opencv2/flann/any.h +++ b/modules/flann/include/opencv2/flann/any.h @@ -255,8 +255,7 @@ public: const T& cast() const { if (policy->type() != typeid(T)) throw anyimpl::bad_any_cast(); - void* obj = const_cast(object); - T* r = reinterpret_cast(policy->get_value(&obj)); + T* r = reinterpret_cast(policy->get_value(const_cast(&object))); return *r; }