Skip to content

Commit e4620f6

Browse files
authored
[SYCL][XPTI] Fix off-by-one error in USMAnalyzer (#13936)
When looking for the correct allocation, the upper bound check was inclusive (Ptr <= Alloc.first + Alloc.second.Length). If we have two allocations back-to-back, the pointer to the beginning of the second allocation would incorrectly be determined as belonging to the first allocation. This caused false-positives errors about out-of-bounds memory operations.
1 parent ff7cf16 commit e4620f6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sycl/tools/xpti_helpers/usm_analyzer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class USMAnalyzer {
6161
const void *End =
6262
static_cast<const char *>(Alloc.first) + Alloc.second.Length;
6363

64-
if (PtrToValidate >= Begin && PtrToValidate <= End) {
64+
if (PtrToValidate >= Begin && PtrToValidate < End) {
6565
PointerFound = true;
6666
const void *CopyRegionEnd =
6767
static_cast<const char *>(PtrToValidate) + size;
@@ -138,7 +138,7 @@ class USMAnalyzer {
138138
const void *Begin = Alloc.first;
139139
const void *End =
140140
static_cast<const char *>(Alloc.first) + Alloc.second.Length;
141-
if (PtrToValidate >= Begin && PtrToValidate <= End) {
141+
if (PtrToValidate >= Begin && PtrToValidate < End) {
142142
PointerFound = true;
143143
const void *CopyRegionEnd =
144144
static_cast<const char *>(PtrToValidate) + pitch * length;
@@ -338,7 +338,7 @@ class USMAnalyzer {
338338
const void *End =
339339
static_cast<const char *>(Alloc.first) + Alloc.second.Length;
340340
// Host pointer was allocated with USM APIs
341-
if (HostPtr >= Begin && HostPtr <= End) {
341+
if (HostPtr >= Begin && HostPtr < End) {
342342
bool NeedsTerminate = false;
343343
if (Alloc.second.Kind != AllocKind::host) {
344344
OutStream << PrintPrefix

0 commit comments

Comments
 (0)