Parcourir la source

use snprintf instead of sprintf

Nathalie Furmento il y a 8 ans
Parent
commit
4b156e1175

+ 2 - 2
examples/spmv/matrix_market/mmio.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2013, 2014, 2016  CNRS
+ * Copyright (C) 2010, 2013, 2014, 2016, 2017  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
@@ -482,6 +482,6 @@ char  *mm_typecode_to_str(MM_typecode matcode)
 	else
 		return NULL;
 
-	sprintf(buffer,"%s %s %s %s", types[0], types[1], types[2], types[3]);
+	snprintf(buffer, sizeof(buffer), "%s %s %s %s", types[0], types[1], types[2], types[3]);
 	return mm_strdup(buffer);
 }

+ 1 - 1
src/core/disk_ops/disk_hdf5.c

@@ -486,7 +486,7 @@ static void *starpu_hdf5_alloc(void *base, size_t size)
 
         /* Save the name of the dataset */
         STARPU_PTHREAD_MUTEX_LOCK(&fileBase->mutex);
-        sprintf(name_id, "%u", fileBase->next_dataset_id);
+        snprintf(name_id, sizeof(name_id), "%u", fileBase->next_dataset_id);
         fileBase->next_dataset_id++;
         STARPU_PTHREAD_MUTEX_UNLOCK(&fileBase->mutex);
 

+ 2 - 2
src/core/topology.c

@@ -586,12 +586,12 @@ _starpu_init_mic_node (struct _starpu_machine_config *config, int mic_idx,
 	 * of node it is (architecture and type) as there is no way to discover
 	 * it itself */
 	char mic_idx_env[32];
-	sprintf(mic_idx_env, "_STARPU_MIC_DEVID=%d", mic_idx);
+	snprintf(mic_idx_env, sizeof(mic_idx_env), "_STARPU_MIC_DEVID=%d", mic_idx);
 
 	/* XXX: this is currently necessary so that the remote process does not
 	 * segfault. */
 	char nb_mic_env[32];
-	sprintf(nb_mic_env, "_STARPU_MIC_NB=%d", 2);
+	snprintf(nb_mic_env, sizeof(nb_mic_env), "_STARPU_MIC_NB=%d", 2);
 
 	const char *mic_sink_env[] = {"STARPU_SINK=STARPU_MIC", mic_idx_env, nb_mic_env, NULL};
 

+ 1 - 1
src/drivers/cpu/driver_cpu.c

@@ -173,7 +173,7 @@ static size_t _starpu_cpu_get_global_mem_size(int nodeid STARPU_ATTRIBUTE_UNUSED
 		{
 			hwloc_obj_t obj = hwloc_get_obj_by_depth(topology->hwtopology, depth_node, nodeid);
 			global_mem = obj->memory.local_memory;
-			sprintf(name, "STARPU_LIMIT_CPU_NUMA_%d_MEM", obj->os_index);
+			snprintf(name, sizeof(name), "STARPU_LIMIT_CPU_NUMA_%d_MEM", obj->os_index);
 			limit = starpu_get_env_number(name);
 		}
 	}

+ 1 - 1
src/drivers/cuda/driver_cuda.c

@@ -132,7 +132,7 @@ static void _starpu_cuda_limit_gpu_mem_if_needed(unsigned devid)
 	if (limit == -1)
 	{
 		char name[30];
-		sprintf(name, "STARPU_LIMIT_CUDA_%u_MEM", devid);
+		snprintf(name, sizeof(name), "STARPU_LIMIT_CUDA_%u_MEM", devid);
 		limit = starpu_get_env_number(name);
 	}
 #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)

+ 2 - 2
tests/main/starpu_init.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2012, 2013, 2014  CNRS
+ * Copyright (C) 2012, 2013, 2014, 2017  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
@@ -40,7 +40,7 @@ static int check_cpu(int env_cpu, int conf_cpu, int expected_cpu, int *cpu)
 	if (env_cpu != -1)
 	{
 		char string[10];
-		sprintf(string, "%d", env_cpu);
+		snprintf(string, sizeof(string), "%d", env_cpu);
 		setenv("STARPU_NCPUS", string, 1);
 	}
 

+ 2 - 2
tests/microbenchs/matrix_as_vector.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2012, 2013, 2014  CNRS
+ * Copyright (C) 2012, 2013, 2014, 2017  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
@@ -159,7 +159,7 @@ int check_size(int nx, struct starpu_codelet *vector_codelet, struct starpu_code
 			{
 				char file[1024];
 				FILE *f;
-				sprintf(file, "%s/matrix_as_vector_%s.dat", output_dir, device_name);
+				snprintf(file, sizeof(file), "%s/matrix_as_vector_%s.dat", output_dir, device_name);
 				f = fopen(file, "a");
 				fprintf(f, "%s\t%d\t%f\t%f\n", bench_id, nx, vector_timing, matrix_timing);
 				fclose(f);