Przeglądaj źródła

minor fixes for bugs spotted by static analyser

Nathalie Furmento 7 lat temu
rodzic
commit
fab13bc6f7
2 zmienionych plików z 15 dodań i 15 usunięć
  1. 4 4
      socl/src/cl_buildprogram.c
  2. 11 11
      src/drivers/opencl/driver_opencl_utils.c

+ 4 - 4
socl/src/cl_buildprogram.c

@@ -1,8 +1,8 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2011-2012                                Inria
- * Copyright (C) 2012,2016-2017                           CNRS
- * Copyright (C) 2010-2012, 2018                                Université de Bordeaux
+ * Copyright (C) 2012,2016-2018                           CNRS
+ * Copyright (C) 2010-2012, 2018                          Université de Bordeaux
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -57,8 +57,8 @@ static void soclBuildProgram_task(void *data)
 			       dev_type == CL_DEVICE_TYPE_ACCELERATOR ? "ACCELERATOR" : "UNKNOWN");
 
 	char opts[4096];
-	sprintf(opts, "-DSOCL_DEVICE_TYPE_%s %s",
-		dev_type_str, (d->options != NULL ? d->options : ""));
+	snprintf(opts, sizeof(opts), "-DSOCL_DEVICE_TYPE_%s %s",
+		 dev_type_str, (d->options != NULL ? d->options : ""));
 
 	err = clBuildProgram(d->program->cl_programs[range], 1, &device, opts, NULL, NULL);
 	if (err != CL_SUCCESS)

+ 11 - 11
src/drivers/opencl/driver_opencl_utils.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2011-2012,2016                           Inria
  * Copyright (C) 2010-2017                                Université de Bordeaux
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2018                                CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -55,14 +55,14 @@ int _starpu_opencl_locate_file(const char *source_file_name, char **located_file
 	if (access(source_file_name, R_OK) == 0)
 	{
 		_STARPU_CALLOC(*located_file_name, 1, strlen(source_file_name)+1);
-		sprintf(*located_file_name, "%s", source_file_name);
+		snprintf(*located_file_name, strlen(source_file_name)+1, "%s", source_file_name);
 		ret = EXIT_SUCCESS;
 	}
 
 	if (ret == EXIT_FAILURE && _starpu_opencl_program_dir)
 	{
 		_STARPU_CALLOC(*located_file_name, 1, strlen(_starpu_opencl_program_dir)+1+strlen(source_file_name)+1);
-		sprintf(*located_file_name, "%s/%s", _starpu_opencl_program_dir, source_file_name);
+		snprintf(*located_file_name, strlen(_starpu_opencl_program_dir)+1+strlen(source_file_name)+1, "%s/%s", _starpu_opencl_program_dir, source_file_name);
 		_STARPU_DEBUG("Trying to locate <%s>\n", *located_file_name);
 		if (access(*located_file_name, R_OK) == 0)
 			ret = EXIT_SUCCESS;
@@ -71,7 +71,7 @@ int _starpu_opencl_locate_file(const char *source_file_name, char **located_file
 	if (ret == EXIT_FAILURE)
 	{
 		_STARPU_CALLOC(*located_file_name, 1, strlen(STARPU_SRC_DIR)+1+strlen(source_file_name)+1);
-		sprintf(*located_file_name, "%s/%s", STARPU_SRC_DIR, source_file_name);
+		snprintf(*located_file_name, strlen(STARPU_SRC_DIR)+1+strlen(source_file_name)+1, "%s/%s", STARPU_SRC_DIR, source_file_name);
 		_STARPU_DEBUG("Trying to locate <%s>\n", *located_file_name);
 		if (access(*located_file_name, R_OK) == 0)
 			ret = EXIT_SUCCESS;
@@ -80,7 +80,7 @@ int _starpu_opencl_locate_file(const char *source_file_name, char **located_file
 	if (ret == EXIT_FAILURE)
 	{
 		_STARPU_CALLOC(*located_file_name, 1, strlen(_STARPU_STRINGIFY(STARPU_OPENCL_DATADIR))+1+strlen(source_file_name)+1);
-		sprintf(*located_file_name, "%s/%s", _STARPU_STRINGIFY(STARPU_OPENCL_DATADIR), source_file_name);
+		snprintf(*located_file_name, strlen(_STARPU_STRINGIFY(STARPU_OPENCL_DATADIR))+1+strlen(source_file_name)+1, "%s/%s", _STARPU_STRINGIFY(STARPU_OPENCL_DATADIR), source_file_name);
 		_STARPU_DEBUG("Trying to locate <%s>\n", *located_file_name);
 		if (access(*located_file_name, R_OK) == 0)
 			ret = EXIT_SUCCESS;
@@ -97,12 +97,12 @@ int _starpu_opencl_locate_file(const char *source_file_name, char **located_file
 		if (!last)
 		{
 			_STARPU_CALLOC(*located_dir_name, 2, sizeof(char));
-			sprintf(*located_dir_name, "%s", "");
+			snprintf(*located_dir_name, 2, "%s", "");
 		}
 		else
 		{
 			_STARPU_CALLOC(*located_dir_name, 1, 1+strlen(*located_file_name));
-			sprintf(*located_dir_name, "%s", *located_file_name);
+			snprintf(*located_dir_name, 1+strlen(*located_file_name), "%s", *located_file_name);
 			(*located_dir_name)[strlen(*located_file_name)-strlen(last)+1] = '\0';
 		}
 	}
@@ -244,7 +244,7 @@ int _starpu_opencl_get_binary_name(char *binary_file_name, size_t maxlen, const
 	cl_int err;
 	cl_uint vendor_id;
 
-	_starpu_opencl_create_binary_directory(binary_directory, 1024);
+	_starpu_opencl_create_binary_directory(binary_directory, sizeof(binary_file_name));
 
 	p = strrchr(source_file_name, '/');
 	snprintf(binary_file_name, maxlen, "%s/%s", binary_directory, p?p:source_file_name);
@@ -338,7 +338,7 @@ int _starpu_opencl_compile_or_load_opencl_from_string(const char *opencl_program
 			size_t binary_len;
 			FILE *fh;
 
-			err = _starpu_opencl_get_binary_name(binary_file_name, 1024, source_file_name, dev, device);
+			err = _starpu_opencl_get_binary_name(binary_file_name, sizeof(binary_file_name), source_file_name, dev, device);
 			if (STARPU_UNLIKELY(err != CL_SUCCESS)) STARPU_OPENCL_REPORT_ERROR(err);
 
 			err = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &binary_len, NULL);
@@ -380,7 +380,7 @@ void starpu_opencl_load_program_source_malloc(const char *source_file_name, char
 		_STARPU_ERROR("Failed to load compute program from file <%s>!\n", *located_file_name);
 
 	_STARPU_MALLOC(*opencl_program_source, strlen(source)+1);
-	sprintf(*opencl_program_source, "%s", source);
+	snprintf(*opencl_program_source, strlen(source)+1, "%s", source);
 	free(source);
 }
 
@@ -498,7 +498,7 @@ int starpu_opencl_load_binary_opencl(const char *kernel_id, struct starpu_opencl
 		}
 
 		// Load the binary buffer
-		err = _starpu_opencl_get_binary_name(binary_file_name, 1024, kernel_id, dev, device);
+		err = _starpu_opencl_get_binary_name(binary_file_name, sizeof(binary_file_name), kernel_id, dev, device);
 		if (STARPU_UNLIKELY(err != CL_SUCCESS)) STARPU_OPENCL_REPORT_ERROR(err);
 		binary = _starpu_opencl_load_program_binary(binary_file_name, &length);