From cb13e0786a4f47ce30ab683726bb210f81d5a038 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Mon, 3 Aug 2015 11:40:57 -0700 Subject: [PATCH] Fixed the checked_guard/nil_guard to pass by reference This fix should allow checked_guard to properly pass by reference rather than pulling everything out to a copy. This should ensure that out parameters are possible in the C++ stack, though still extremely discouraged. Change-Id: Ide35e9eb7adbdd532f375f341286387a641e8436 Signed-off-by: Erich Keane Reviewed-on: https://gerrit.iotivity.org/gerrit/2087 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- resource/include/OCUtilities.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/resource/include/OCUtilities.h b/resource/include/OCUtilities.h index 65ea6af..87bdf35 100644 --- a/resource/include/OCUtilities.h +++ b/resource/include/OCUtilities.h @@ -78,8 +78,11 @@ namespace OC { throw OCException(OC::Exception::NIL_GUARD_NULL, OC_STACK_INVALID_PARAM); } - // Note that although parameters are being forwarded, std::bind() will make a single copy: - return std::bind(fn, p, std::forward(params)...)(); + // Note that the parameters are being passed by reference to std::bind. This is not an + // issue, as it is this function's parameters that are being passed by reference. So, + // unless the parameters are being passed by reference to here (or to checked_guard), + // they won't be modified. + return std::bind(fn, p, std::ref(params)...)(); } /* Check for nullptr and forward the result of an OC function call on success; raise -- 2.7.4