Mercurial > octave
changeset 24710:a979bb895b64
avoid reinterpret_cast on function pointer in previous change
* sysdep.cc (reg_close_key_wrapper): New function.
(get_regkey_value): Use it with unwind_protect instead of casting
function pointer.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Feb 2018 16:20:41 -0500 |
parents | 6a6108db3a6b |
children | 752f61e812f4 |
files | libinterp/corefcn/sysdep.cc |
diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/sysdep.cc Thu Feb 08 19:56:18 2018 +0100 +++ b/libinterp/corefcn/sysdep.cc Thu Feb 08 16:20:41 2018 -0500 @@ -713,6 +713,13 @@ */ #if defined (OCTAVE_USE_WINDOWS_API) + +static void +reg_close_key_wrapper (HKEY key) +{ + RegCloseKey (key); +} + LONG get_regkey_value (HKEY h_rootkey, const std::string subkey, const std::string name, octave_value& value) @@ -720,15 +727,13 @@ LONG result; HKEY h_subkey; - octave::unwind_protect frame; - result = RegOpenKeyExA (h_rootkey, subkey.c_str (), 0, KEY_READ, &h_subkey); if (result != ERROR_SUCCESS) return result; - // Cast return value to void - typedef void (*f_ptr)(HKEY); - frame.add_fcn (reinterpret_cast<f_ptr> (RegCloseKey), h_subkey); + octave::unwind_protect frame; + + frame.add_fcn (reg_close_key_wrapper, h_subkey); DWORD length = 0; result = RegQueryValueExA (h_subkey, name.c_str (), nullptr, nullptr, nullptr,