Skip to content

Commit

Permalink
Use RARRAY_LENINT instead of casting
Browse files Browse the repository at this point in the history
This ensures the int value range is not exceeded.
  • Loading branch information
larskanis committed Apr 22, 2024
1 parent d006232 commit 7d400a3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ext/ffi_c/FunctionInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fntype_initialize(int argc, VALUE* argv, VALUE self)
Check_Type(rbParamTypes, T_ARRAY);

TypedData_Get_Struct(self, FunctionType, &rbffi_fntype_data_type, fnInfo);
fnInfo->parameterCount = (int) RARRAY_LEN(rbParamTypes);
fnInfo->parameterCount = RARRAY_LENINT(rbParamTypes);
fnInfo->parameterTypes = xcalloc(fnInfo->parameterCount, sizeof(*fnInfo->parameterTypes));
fnInfo->ffiParameterTypes = xcalloc(fnInfo->parameterCount, sizeof(ffi_type *));
fnInfo->nativeParameterTypes = xcalloc(fnInfo->parameterCount, sizeof(*fnInfo->nativeParameterTypes));
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/StructLayout.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align)
int i;

TypedData_Get_Struct(self, StructLayout, &rbffi_struct_layout_data_type, layout);
layout->fieldCount = (int) RARRAY_LEN(fields);
layout->fieldCount = RARRAY_LENINT(fields);
RB_OBJ_WRITE(self, &layout->rbFieldMap, rb_hash_new());
RB_OBJ_WRITE(self, &layout->rbFieldNames, rb_ary_new2(layout->fieldCount));
layout->size = (int) FFI_ALIGN(NUM2INT(size), NUM2INT(align));
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi_c/Variadic.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ variadic_invoke(VALUE self, VALUE parameterTypes, VALUE parameterValues)
Check_Type(parameterValues, T_ARRAY);

TypedData_Get_Struct(self, VariadicInvoker, &variadic_data_type, invoker);
paramCount = (int) RARRAY_LEN(parameterTypes);
paramCount = RARRAY_LENINT(parameterTypes);
paramTypes = ALLOCA_N(Type *, paramCount);
ffiParamTypes = ALLOCA_N(ffi_type *, paramCount);
params = ALLOCA_N(FFIStorage, paramCount);
Expand Down

0 comments on commit 7d400a3

Please sign in to comment.