Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix casts to not be undefined behavior #1070

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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