From cf8dbfb39f967ac642f5aef890d9e0dd02b9fd5a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 15 Sep 2021 11:33:48 +0200 Subject: [PATCH 1/3] src: fix casts to not be undefined behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- napi-inl.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/napi-inl.h b/napi-inl.h index a1d67ac17..db7146c39 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -2044,8 +2044,10 @@ inline TypedArrayOf::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(&_data), nullptr, nullptr); + _env, _value, &_type, &_length, &data, nullptr, nullptr); + _data = static_cast(data); } else { _type = TypedArrayTypeForPrimitiveType(); _length = 0; @@ -3967,10 +3969,10 @@ inline ObjectWrap::~ObjectWrap() { template inline T* ObjectWrap::Unwrap(Object wrapper) { - T* unwrapped; - napi_status status = napi_unwrap(wrapper.Env(), wrapper, reinterpret_cast(&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(unwrapped); } template From a8944c1d5db7b2cc6b5024fa6cb155f3bc3a3a1a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 15 Sep 2021 11:36:09 +0200 Subject: [PATCH 2/3] fixup: lint --- napi-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napi-inl.h b/napi-inl.h index db7146c39..0b84a5a27 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -2046,7 +2046,7 @@ inline TypedArrayOf::TypedArrayOf(napi_env env, napi_value value) if (value != nullptr) { void* data = nullptr; status = napi_get_typedarray_info( - _env, _value, &_type, &_length, &data, nullptr, nullptr); + _env, _value, &_type, &_length, &data, nullptr, nullptr); _data = static_cast(data); } else { _type = TypedArrayTypeForPrimitiveType(); From 141b99514bbce8d7e7d425ac98a68ef7d7c4f317 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 15 Sep 2021 13:05:12 +0200 Subject: [PATCH 3/3] fixup: trailing whitespace --- napi-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napi-inl.h b/napi-inl.h index 0b84a5a27..0af8e7ae5 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -2046,7 +2046,7 @@ inline TypedArrayOf::TypedArrayOf(napi_env env, napi_value value) if (value != nullptr) { void* data = nullptr; status = napi_get_typedarray_info( - _env, _value, &_type, &_length, &data, nullptr, nullptr); + _env, _value, &_type, &_length, &data, nullptr, nullptr); _data = static_cast(data); } else { _type = TypedArrayTypeForPrimitiveType();