Guard nullptr dereference (#1972)

* guard nullptr dereference

* comment
This commit is contained in:
Awni Hannun 2025-03-19 16:24:10 -07:00 committed by GitHub
parent 3779150750
commit f90206ad74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View File

@ -20,6 +20,9 @@ Allocator& allocator() {
} }
void* Buffer::raw_ptr() { void* Buffer::raw_ptr() {
if (!ptr_) {
return nullptr;
}
return static_cast<MTL::Buffer*>(ptr_)->contents(); return static_cast<MTL::Buffer*>(ptr_)->contents();
} }

View File

@ -10,6 +10,9 @@ Allocator& allocator() {
} }
void* Buffer::raw_ptr() { void* Buffer::raw_ptr() {
if (!ptr_) {
return nullptr;
}
return static_cast<size_t*>(ptr_) + 1; return static_cast<size_t*>(ptr_) + 1;
} }