From a4e5f6565925654b874d60a9a58c572f0d376eb4 Mon Sep 17 00:00:00 2001 From: Howard Su Date: Sat, 27 May 2023 21:04:42 +0800 Subject: [PATCH] Ensure ext_buffer is null terminated --- ggml-opencl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ggml-opencl.cpp b/ggml-opencl.cpp index e0b1cb78f..8f2e5fbca 100644 --- a/ggml-opencl.cpp +++ b/ggml-opencl.cpp @@ -469,8 +469,9 @@ void ggml_cl_init(void) { size_t ext_str_size; clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &ext_str_size); - char *ext_buffer = (char *)alloca(ext_str_size); + char *ext_buffer = (char *)alloca(ext_str_size + 1); clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, ext_str_size, ext_buffer, NULL); + ext_buffer[ext_str_size] = '\0'; // ensure it is null terminated // Check if ext_buffer contains cl_khr_fp16 fp16_support = strstr(ext_buffer, "cl_khr_fp16") != NULL; fprintf(stderr, "ggml_opencl: device FP16 support: %s\n", fp16_support ? "true" : "false");