ruby-rice / rice

Ruby Interface for C++ Extensions
http://ruby-rice.github.io/
Other
378 stars 63 forks source link

Fix undefined behavior #130

Closed cfis closed 3 years ago

cfis commented 3 years ago

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 although with GCC it works fine in a debug mode (but per the C++ spec you aren't supposed to do that). 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.

jasonroelofs commented 3 years ago

Thanks for the fix! This change looks fine to me. CI passes fine (https://travis-ci.org/github/jasonroelofs/rice/builds/749963667) though that doesn't seem to be reporting here anymore, probably due to upcoming changes to Travis.

I will make some time this holiday to finalize a few things and actually get a new release out.