Commit 4524014 1 parent b8cb3da commit 4524014 Copy full SHA for 4524014
File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ class InstanceData final : public RefNapi::Instance {
140
140
if (it != pointer_to_orig_buffer.end ())
141
141
ab = it->second .ab .Value ();
142
142
143
- if (ab.IsEmpty ()) {
143
+ if (ab.IsEmpty () || (ab. ByteLength () < length) ) {
144
144
// this ALWAYS creates an arraybuffer of 1Gbyte?
145
145
// length = std::max<size_t>(length, kMaxLength);
146
146
length = std::min<size_t >(length, kMaxLength );
@@ -168,8 +168,15 @@ class InstanceData final : public RefNapi::Instance {
168
168
*/
169
169
170
170
Value WrapPointer (Env env, char * ptr, size_t length) {
171
- if (ptr == nullptr )
171
+ if (ptr == nullptr ) {
172
172
length = 0 ;
173
+ } else if (length == 0 ) {
174
+ // If length is 0 N-API doesn't guarantee it will save/restore ptr normally.
175
+ // For example, see https://nodejs.org/api/n-api.html#napi_get_typedarray_info
176
+ // "[out] data: ... If the length of the array is 0, this may be NULL or any
177
+ // other pointer value."
178
+ length = 1 ;
179
+ }
173
180
174
181
InstanceData* data;
175
182
if (ptr != nullptr && (data = InstanceData::Get (env)) != nullptr ) {
You can’t perform that action at this time.
0 commit comments