Skip to content

Commit 116db44

Browse files
[SYCL][NFC] Remove end iterator dereference in unit tests (#7031)
Dereferencing vector::end() is UB and leads to errors in debug Windows builds.
1 parent 1d99344 commit 116db44

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sycl/unittests/helpers/PiImage.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,20 @@ template <typename T> class PiArray {
129129
updateEntries();
130130
}
131131

132+
if (MEntries.empty())
133+
return nullptr;
134+
132135
return &*MEntries.begin();
133136
}
134137
typename T::NativeType *end() {
135138
if (MEntriesNeedUpdate) {
136139
updateEntries();
137140
}
138-
return &*MEntries.end();
141+
142+
if (MEntries.empty())
143+
return nullptr;
144+
145+
return &*MEntries.rbegin() + 1;
139146
}
140147

141148
private:
@@ -176,7 +183,7 @@ class PiPropertySet {
176183
_pi_device_binary_property_set_struct *end() {
177184
if (MProperties.empty())
178185
return nullptr;
179-
return &*MProperties.end();
186+
return &*MProperties.rbegin() + 1;
180187
}
181188

182189
private:

0 commit comments

Comments
 (0)