Skip to content

Commit

Permalink
ggml : fix null backend dereference (#4807)
Browse files Browse the repository at this point in the history
* ggml : fix null backend dereference

* ggml : also check ggml_backend_is_cpu
  • Loading branch information
ggerganov authored Jan 7, 2024
1 parent 72b74f3 commit f77c72f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ggml-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ ggml_backend_t ggml_backend_cpu_init(void) {
}

bool ggml_backend_is_cpu(ggml_backend_t backend) {
return backend->iface.get_name == ggml_backend_cpu_name;
return backend && backend->iface.get_name == ggml_backend_cpu_name;
}

void ggml_backend_cpu_set_n_threads(ggml_backend_t backend_cpu, int n_threads) {
Expand Down
2 changes: 1 addition & 1 deletion ggml-cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -10140,7 +10140,7 @@ ggml_backend_t ggml_backend_cuda_init(int device) {
}

bool ggml_backend_is_cuda(ggml_backend_t backend) {
return backend->iface.get_name == ggml_backend_cuda_name;
return backend && backend->iface.get_name == ggml_backend_cuda_name;
}

int ggml_backend_cuda_get_device_count() {
Expand Down
2 changes: 1 addition & 1 deletion ggml-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,7 @@ ggml_backend_t ggml_backend_metal_init(void) {
}

bool ggml_backend_is_metal(ggml_backend_t backend) {
return backend->iface.get_name == ggml_backend_metal_name;
return backend && backend->iface.get_name == ggml_backend_metal_name;
}

void ggml_backend_metal_set_n_cb(ggml_backend_t backend, int n_cb) {
Expand Down

0 comments on commit f77c72f

Please sign in to comment.