TooTallNate / ref

Turn Buffer instances into "pointers"
http://tootallnate.github.com/ref
453 stars 141 forks source link

Corner case: will not match NULL #49

Open kuldeepdhaka opened 8 years ago

kuldeepdhaka commented 8 years ago

https://github.com/TooTallNate/ref/blob/master/src/binding.cc#L514

  int64_t offset = GetInt64(info[2]);
  char *ptr = Buffer::Data(buf.As<Object>()) + offset;

  if (ptr == NULL) {
    return Nan::ThrowError("reinterpret: Cannot reinterpret from NULL pointer");
  }

if offset > 0 then checking ptr == NULL will not match even if Buffer::Data(buf.As<Object>()) return NULL

etiher checking is useless or we need to check for NULL before adding offset.

TooTallNate commented 8 years ago

Ya good point we should deprecate the parameter with a warning and then remove it in the next major version.

TooTallNate commented 8 years ago

PR welcome.

kuldeepdhaka commented 8 years ago

probebly removing offset is a good idea. also, offset can be applied using Buffer.slice (which uses TypedArray subarray())

kuldeepdhaka commented 8 years ago

BUT adding offset and NULL checking style is used through out the c++ code. better is to remove from everywhere. (present in ReadObject, ReadPointer, ReadInt64, ReadUInt64, ReadCString also) This would require considerable api change