Skip to content

Commit cb592f0

Browse files
committed
load.c: Fix dest and src of MEMMOVE
When multiple files with the same name are required, the features_index hash stores the indexes in `$LOADED_FEATURES` array into a darray. The dest and src arguments for `MEMMOVE` were wrongly reversed when inserting a new index in the darray. [Bug #21568]
1 parent 88222ca commit cb592f0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

load.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ features_index_add_single_callback(st_data_t *key, st_data_t *value, st_data_t r
268268
if (pos >= 0) {
269269
long *ptr = rb_darray_data_ptr(feature_indexes);
270270
long len = rb_darray_size(feature_indexes);
271-
MEMMOVE(ptr + pos, ptr + pos + 1, long, len - pos - 1);
271+
MEMMOVE(ptr + pos + 1, ptr + pos, long, len - pos - 1);
272272
ptr[pos] = FIX2LONG(offset);
273273
}
274274
}

test/ruby/test_require.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,4 +1035,18 @@ class Object
10351035
end
10361036
RUBY
10371037
end
1038+
1039+
def test_bug_21568
1040+
load_path = $LOAD_PATH.dup
1041+
loaded_featrures = $LOADED_FEATURES.dup
1042+
1043+
$LOAD_PATH.clear
1044+
$LOADED_FEATURES.replace(["foo.so", "a/foo.rb", "b/foo.rb"])
1045+
1046+
assert_nothing_raised(LoadError) { require "foo" }
1047+
1048+
ensure
1049+
$LOAD_PATH.replace(load_path) if load_path
1050+
$LOADED_FEATURES.replace loaded_featrures
1051+
end
10381052
end

0 commit comments

Comments
 (0)