diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-09-03 02:48:26 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-09-03 02:48:26 -0400 |
| commit | 806c87d71dd3c5f173c932062d044f9bf8e0e3db (patch) | |
| tree | 7577df9bd040e455a59966f1ed4fc177ad775391 /core/slice | |
| parent | 71b2527df07a8628093792bbf2a7886bed253a09 (diff) | |
Check for zero-length slices in `slice.equal`
Diffstat (limited to 'core/slice')
| -rw-r--r-- | core/slice/slice.odin | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/slice/slice.odin b/core/slice/slice.odin index 989fcc696..99ad15547 100644 --- a/core/slice/slice.odin +++ b/core/slice/slice.odin @@ -200,6 +200,17 @@ equal :: proc(a, b: $T/[]$E) -> bool where intrinsics.type_is_comparable(E) #no_ return false } when intrinsics.type_is_simple_compare(E) { + if len(a) == 0 { + // Empty slices are always equivalent to each other. + // + // This check is here in the event that a slice with a `data` of + // nil is compared against a slice with a non-nil `data` but a + // length of zero. + // + // In that case, `memory_compare` would return -1 or +1 because one + // of the pointers is nil. + return true + } return runtime.memory_compare(raw_data(a), raw_data(b), len(a)*size_of(E)) == 0 } else { for i in 0..<len(a) { |