Skip to content

Commit

Permalink
SHA-1: ac86884a986d3b1d75dc16b7da5b527cd5a65d30
Browse files Browse the repository at this point in the history
* Fix undefined behavior. When the number of arguments to a method call is 0, then the asList vector has a size of zero. In that case, calling asList[0] is undefined behavior. On MSVC in debug mode that causes a crash. Instead, data() should be used instead. Note a second way of solving this would be to specialize the call template like this:

template<>
inline Rice::Object Rice::Object::
call(Identifier id) const
{
    return protect(rb_funcall, value(), id, 0);
}

I like that better but it seemed like a more invasive change.
  • Loading branch information
cfis committed Dec 16, 2020
1 parent 4bae186 commit 1c57715
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rice/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ vcall(
a[i] = it->value();
}

return protect(rb_funcall3, *this, id, (int)args.size(), &a[0]);
return protect(rb_funcall3, *this, id, (int)args.size(), a.data());
}

void Rice::Object::
Expand Down
2 changes: 1 addition & 1 deletion rice/Object.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inline Rice::Object Rice::Object::
call(Identifier id, ArgT... args) const
{
auto asList = this->convert_args<ArgT...>(args...);
return protect(rb_funcall2, value(), id, (int)asList.size(), &asList[0]);
return protect(rb_funcall2, value(), id, (int)asList.size(), asList.data());
}

template<typename ...ArgT>
Expand Down

0 comments on commit 1c57715

Please sign in to comment.