From f77c72f3718711ce2f29787e40ec4638e2be6db8 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 7 Jan 2024 13:06:57 +0200 Subject: [PATCH] ggml : fix null backend dereference (#4807) * ggml : fix null backend dereference * ggml : also check ggml_backend_is_cpu --- ggml-backend.c | 2 +- ggml-cuda.cu | 2 +- ggml-metal.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ggml-backend.c b/ggml-backend.c index 56f96c367..8d66c5605 100644 --- a/ggml-backend.c +++ b/ggml-backend.c @@ -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) { diff --git a/ggml-cuda.cu b/ggml-cuda.cu index 032d7e986..ee82f68d7 100644 --- a/ggml-cuda.cu +++ b/ggml-cuda.cu @@ -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() { diff --git a/ggml-metal.m b/ggml-metal.m index e3d76b9d3..00b377a3e 100644 --- a/ggml-metal.m +++ b/ggml-metal.m @@ -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) {