Skip to content

Commit

Permalink
Make empty range options and keys valid
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Jan 30, 2022
1 parent 00e5584 commit e99a0af
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static std::string* RangeOption (napi_env env, napi_value opts, const char* name
if (HasProperty(env, opts, name)) {
napi_value value = GetProperty(env, opts, name);

if (StringOrBufferLength(env, value) > 0) {
if (StringOrBufferLength(env, value) >= 0) {
LD_STRING_OR_BUFFER_TO_COPY(env, value, to);
std::string* result = new std::string(toCh_, toSz_);
delete [] toCh_;
Expand All @@ -244,7 +244,6 @@ static std::string* RangeOption (napi_env env, napi_value opts, const char* name

/**
* Converts an array containing Buffer or string keys to a vector.
* Empty elements are skipped.
*/
static std::vector<std::string>* KeyArray (napi_env env, napi_value arr) {
uint32_t length;
Expand All @@ -257,7 +256,7 @@ static std::vector<std::string>* KeyArray (napi_env env, napi_value arr) {
napi_value element;

if (napi_get_element(env, arr, i, &element) == napi_ok &&
StringOrBufferLength(env, element) > 0) {
StringOrBufferLength(env, element) >= 0) {
LD_STRING_OR_BUFFER_TO_COPY(env, element, to);
result->emplace_back(toCh_, toSz_);
}
Expand Down

2 comments on commit e99a0af

@CMCDragonkai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StringOrBufferLength appears to always return an unsigned number. Therefore isn't this condition always true?

@vweevers
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this can be removed. PR is welcome

Please sign in to comment.