From 77e9b1c2e8b3120d9c700ac9c792f75ca5a73c22 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 26 Jan 2012 13:06:39 +1100 Subject: [PATCH] Use calloced stack memory for CompilerOptions to ensure sprintf writes to the beginning of the char. --- ocl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ocl.c b/ocl.c index 3b601e6c..81ffe0bb 100644 --- a/ocl.c +++ b/ocl.c @@ -472,7 +472,7 @@ build: } /* create a cl program executable for all the devices specified */ - char CompilerOptions[256]; + char *CompilerOptions = calloc(1, 256); sprintf(CompilerOptions, "-DWORKSIZE=%d -DVECTORS%d", (int)clState->work_size, clState->preferred_vwidth); @@ -510,7 +510,10 @@ build: } else if (opt_debug) applog(LOG_DEBUG, "BFI_INT patch requiring device not found, will not BFI_INT patch"); + if (opt_debug) + applog(LOG_DEBUG, "CompilerOptions: %s", CompilerOptions); status = clBuildProgram(clState->program, 1, &devices[gpu], CompilerOptions , NULL, NULL); + free(CompilerOptions); if (status != CL_SUCCESS) { applog(LOG_ERR, "Error: Building Program (clBuildProgram)");