Skip to content

Commit

Permalink
src: fix casts to not be undefined behavior
Browse files Browse the repository at this point in the history
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 <midawson@redhat.com>
  • Loading branch information
addaleax authored and mhdawson committed Sep 16, 2021
1 parent 76de4d8 commit 2b57a4a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2044,8 +2044,10 @@ inline TypedArrayOf<T>::TypedArrayOf(napi_env env, napi_value value)
: TypedArray(env, value), _data(nullptr) {
napi_status status = napi_ok;
if (value != nullptr) {
void* data = nullptr;
status = napi_get_typedarray_info(
_env, _value, &_type, &_length, reinterpret_cast<void**>(&_data), nullptr, nullptr);
_env, _value, &_type, &_length, &data, nullptr, nullptr);
_data = static_cast<T*>(data);
} else {
_type = TypedArrayTypeForPrimitiveType<T>();
_length = 0;
Expand Down Expand Up @@ -3967,10 +3969,10 @@ inline ObjectWrap<T>::~ObjectWrap() {

template<typename T>
inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
T* unwrapped;
napi_status status = napi_unwrap(wrapper.Env(), wrapper, reinterpret_cast<void**>(&unwrapped));
void* unwrapped;
napi_status status = napi_unwrap(wrapper.Env(), wrapper, &unwrapped);
NAPI_THROW_IF_FAILED(wrapper.Env(), status, nullptr);
return unwrapped;
return static_cast<T*>(unwrapped);
}

template <typename T>
Expand Down

0 comments on commit 2b57a4a

Please sign in to comment.