浏览代码

Remove unused argument to avoid UB

`OneOfDescriptor_each` is registered as a Ruby method which takes zero
parameters, which means it should take one argument.

When Ruby invokes `OneOfDescriptor_each`, it calls it with one parameter
only, which is one less than what `OneOfDescriptor_each` takes before
this commit. Calling a function with the wrong number of argument is
technically undefined behavior.

See also: §6.5.2.2, N1256
Alan Wu 6 年之前
父节点
当前提交
c1ba7c643c
共有 2 个文件被更改,包括 2 次插入2 次删除
  1. 1 1
      ruby/ext/google/protobuf_c/defs.c
  2. 1 1
      ruby/ext/google/protobuf_c/protobuf.h

+ 1 - 1
ruby/ext/google/protobuf_c/defs.c

@@ -1232,7 +1232,7 @@ VALUE OneofDescriptor_name(VALUE _self) {
  *
  *
  * Iterates through fields in this oneof, yielding to the block on each one.
  * Iterates through fields in this oneof, yielding to the block on each one.
  */
  */
-VALUE OneofDescriptor_each(VALUE _self, VALUE field) {
+VALUE OneofDescriptor_each(VALUE _self) {
   DEFINE_SELF(OneofDescriptor, self, _self);
   DEFINE_SELF(OneofDescriptor, self, _self);
   upb_oneof_iter it;
   upb_oneof_iter it;
   for (upb_oneof_begin(&it, self->oneofdef);
   for (upb_oneof_begin(&it, self->oneofdef);

+ 1 - 1
ruby/ext/google/protobuf_c/protobuf.h

@@ -259,7 +259,7 @@ OneofDescriptor* ruby_to_OneofDescriptor(VALUE value);
 VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
 VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
                                  VALUE descriptor_pool, VALUE ptr);
                                  VALUE descriptor_pool, VALUE ptr);
 VALUE OneofDescriptor_name(VALUE _self);
 VALUE OneofDescriptor_name(VALUE _self);
-VALUE OneofDescriptor_each(VALUE _self, VALUE field);
+VALUE OneofDescriptor_each(VALUE _self);
 
 
 void EnumDescriptor_mark(void* _self);
 void EnumDescriptor_mark(void* _self);
 void EnumDescriptor_free(void* _self);
 void EnumDescriptor_free(void* _self);