Skip to content

Commit 2b57a4a

Browse files
addaleaxmhdawson
authored andcommitted
src: fix casts to not be undefined behavior
I guess if these were broken in practice, V8/Node.js itself would also experience difficulties with it, but there’s no real reason not to use the proper alternatives. PR-URL: #1070 Reviewed-By: Michael Dawson <[email protected]>
1 parent 76de4d8 commit 2b57a4a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

napi-inl.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,8 +2044,10 @@ inline TypedArrayOf<T>::TypedArrayOf(napi_env env, napi_value value)
20442044
: TypedArray(env, value), _data(nullptr) {
20452045
napi_status status = napi_ok;
20462046
if (value != nullptr) {
2047+
void* data = nullptr;
20472048
status = napi_get_typedarray_info(
2048-
_env, _value, &_type, &_length, reinterpret_cast<void**>(&_data), nullptr, nullptr);
2049+
_env, _value, &_type, &_length, &data, nullptr, nullptr);
2050+
_data = static_cast<T*>(data);
20492051
} else {
20502052
_type = TypedArrayTypeForPrimitiveType<T>();
20512053
_length = 0;
@@ -3967,10 +3969,10 @@ inline ObjectWrap<T>::~ObjectWrap() {
39673969

39683970
template<typename T>
39693971
inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
3970-
T* unwrapped;
3971-
napi_status status = napi_unwrap(wrapper.Env(), wrapper, reinterpret_cast<void**>(&unwrapped));
3972+
void* unwrapped;
3973+
napi_status status = napi_unwrap(wrapper.Env(), wrapper, &unwrapped);
39723974
NAPI_THROW_IF_FAILED(wrapper.Env(), status, nullptr);
3973-
return unwrapped;
3975+
return static_cast<T*>(unwrapped);
39743976
}
39753977

39763978
template <typename T>

0 commit comments

Comments
 (0)