Преглед изворни кода

fix bugs reported by coverity

Nathalie Furmento пре 9 година
родитељ
комит
4405cb0795

+ 3 - 2
examples/filters/custom_mf/conversion_opencl.c

@@ -1,6 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2012 INRIA
+ * Copyright (C) 2016 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
@@ -34,7 +35,7 @@ void cpu_to_opencl_opencl_func(void *buffers[], void *args)
 	struct point *aop;
 	aop = (struct point *) CUSTOM_GET_CPU_PTR(buffers[0]);
 
-	id = starpu_worker_get_id();
+	id = starpu_worker_get_id_check();
 	devid = starpu_worker_get_devid(id);
 
 	err = starpu_opencl_load_kernel(&kernel,
@@ -56,7 +57,7 @@ void cpu_to_opencl_opencl_func(void *buffers[], void *args)
 		STARPU_OPENCL_REPORT_ERROR(err);
 		assert(0);
 	}
-	
+
 
 	{
 		size_t global=n;

+ 3 - 2
examples/filters/custom_mf/custom_opencl.c

@@ -1,6 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2012 INRIA
+ * Copyright (C) 2016 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
@@ -33,7 +34,7 @@ void custom_scal_opencl_func(void *buffers[], void *args)
 	struct point *aop;
 	aop = (struct point *) CUSTOM_GET_CPU_PTR(buffers[0]);
 
-	id = starpu_worker_get_id();
+	id = starpu_worker_get_id_check();
 	devid = starpu_worker_get_devid(id);
 
 	err = starpu_opencl_load_kernel(&kernel,
@@ -55,7 +56,7 @@ void custom_scal_opencl_func(void *buffers[], void *args)
 		STARPU_OPENCL_REPORT_ERROR(err);
 		assert(0);
 	}
-	
+
 
 	{
 		size_t global=n;

+ 3 - 3
examples/sched_ctx/sched_ctx.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2014  Université de Bordeaux
- * Copyright (C) 2010-2014  CNRS
+ * Copyright (C) 2010-2014, 2016  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
@@ -29,9 +29,9 @@ starpu_pthread_mutex_t mut;
 
 static void sched_ctx_cpu_func(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg STARPU_ATTRIBUTE_UNUSED)
 {
-	starpu_pthread_mutex_lock(&mut);
+	STARPU_PTHREAD_MUTEX_LOCK(&mut);
 	tasks_executed++;
-	starpu_pthread_mutex_unlock(&mut);
+	STARPU_PTHREAD_MUTEX_UNLOCK(&mut);
 }
 
 static void sched_ctx_cuda_func(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg STARPU_ATTRIBUTE_UNUSED)

+ 10 - 10
examples/scheduler/dummy_sched.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2016  Université de Bordeaux
- * Copyright (C) 2010-2013  CNRS
+ * Copyright (C) 2010-2013, 2016  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
@@ -43,7 +43,7 @@ static void init_dummy_sched(unsigned sched_ctx_id)
 
 	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)data);
 
-	starpu_pthread_mutex_init(&data->policy_mutex, NULL);
+	STARPU_PTHREAD_MUTEX_INIT(&data->policy_mutex, NULL);
 	FPRINTF(stderr, "Initialising Dummy scheduler\n");
 }
 
@@ -53,7 +53,7 @@ static void deinit_dummy_sched(unsigned sched_ctx_id)
 
 	STARPU_ASSERT(starpu_task_list_empty(&data->sched_list));
 
-	starpu_pthread_mutex_destroy(&data->policy_mutex);
+	STARPU_PTHREAD_MUTEX_DESTROY(&data->policy_mutex);
 
 	free(data);
 
@@ -71,12 +71,12 @@ static int push_task_dummy(struct starpu_task *task)
 
 	/* lock all workers when pushing tasks on a list where all
 	   of them would pop for tasks */
-        starpu_pthread_mutex_lock(&data->policy_mutex);
+        STARPU_PTHREAD_MUTEX_LOCK(&data->policy_mutex);
 
 	starpu_task_list_push_front(&data->sched_list, task);
 
 	starpu_push_task_end(task);
-	starpu_pthread_mutex_unlock(&data->policy_mutex);
+	STARPU_PTHREAD_MUTEX_UNLOCK(&data->policy_mutex);
 
 
         /*if there are no tasks block */
@@ -93,9 +93,9 @@ static int push_task_dummy(struct starpu_task *task)
 		starpu_pthread_mutex_t *sched_mutex;
                 starpu_pthread_cond_t *sched_cond;
                 starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
-		starpu_pthread_mutex_lock(sched_mutex);
-                starpu_pthread_cond_signal(sched_cond);
-                starpu_pthread_mutex_unlock(sched_mutex);
+		STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
+                STARPU_PTHREAD_COND_SIGNAL(sched_cond);
+                STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
         }
 
 	return 0;
@@ -110,9 +110,9 @@ static struct starpu_task *pop_task_dummy(unsigned sched_ctx_id)
 	 * the calling worker. So we just take the head of the list and give it
 	 * to the worker. */
 	struct dummy_sched_data *data = (struct dummy_sched_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
-	starpu_pthread_mutex_lock(&data->policy_mutex);
+	STARPU_PTHREAD_MUTEX_LOCK(&data->policy_mutex);
 	struct starpu_task *task = starpu_task_list_pop_back(&data->sched_list);
-	starpu_pthread_mutex_unlock(&data->policy_mutex);
+	STARPU_PTHREAD_MUTEX_UNLOCK(&data->policy_mutex);
 	return task;
 }
 

+ 2 - 2
tests/datawizard/data_invalidation.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010, 2012, 2014, 2016  Université de Bordeaux
- * Copyright (C) 2012, 2013, 2015  CNRS
+ * Copyright (C) 2012, 2013, 2015, 2016  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
@@ -59,7 +59,7 @@ static void opencl_memset_codelet(void *buffers[], void *args)
 	(void) args;
 
 	cl_command_queue queue;
-	int id = starpu_worker_get_id();
+	int id = starpu_worker_get_id_check();
 	int devid = starpu_worker_get_devid(id);
 	starpu_opencl_get_queue(devid, &queue);
 

+ 2 - 0
tests/datawizard/interfaces/multiformat/advanced/multiformat_worker.c

@@ -99,6 +99,8 @@ create_and_submit_tasks(void)
 	else
 #endif
 	{
+		task->destroy = 0;
+		starpu_task_destroy(task);
 		return -ENODEV;
 	}
 

+ 8 - 1
tests/datawizard/manual_reduction.c

@@ -64,9 +64,16 @@ static void initialize_per_worker_handle(void *arg STARPU_ATTRIBUTE_UNUSED)
 #endif
 #ifdef STARPU_USE_CUDA
 		case STARPU_CUDA_WORKER:
-			cudaMalloc((void **)&per_worker[workerid], sizeof(variable));
+		{
+		     	cudaError_t status;
+			status = cudaMalloc((void **)&per_worker[workerid], sizeof(variable));
+			if (!per_worker[workerid] || (status != cudaSuccess))
+			{
+				STARPU_CUDA_REPORT_ERROR(status);
+			}
 			cudaMemset((void *)per_worker[workerid], 0, sizeof(variable));
 			break;
+		}
 #endif
 		default:
 			STARPU_ABORT();

+ 4 - 2
tests/disk/mem_reclaim.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2013 Corentin Salingue
- * Copyright (C) 2015 CNRS
+ * Copyright (C) 2015, 2016 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
@@ -204,8 +204,10 @@ int main(void)
 {
 	int ret = 0;
 	char s[128];
+
 	snprintf(s, sizeof(s), "/tmp/%s-disk-%d", getenv("USER"), getpid());
-	mkdir(s, 0777);
+	ret = mkdir(s, 0777);
+	STARPU_CHECK_RETURN_VALUE(ret, "mkdir '%s'\n", s);
 
 	setenv("STARPU_LIMIT_CPU_MEM", MEMSIZE_STR, 1);
 

+ 3 - 3
tests/microbenchs/async_tasks_overhead.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2014, 2016  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2015  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2015, 2016  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
@@ -161,12 +161,12 @@ int main(int argc, char **argv)
                         char file[1024];
                         FILE *f;
 
-                        sprintf(file, "%s/async_tasks_overhead_total.dat", output_dir);
+                        snprintf(file, 1024, "%s/async_tasks_overhead_total.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, timing/1000000);
                         fclose(f);
 
-                        sprintf(file, "%s/async_tasks_overhead_per_task.dat", output_dir);
+                        snprintf(file, 1024, "%s/async_tasks_overhead_per_task.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, timing/ntasks);
                         fclose(f);

+ 1 - 1
tests/microbenchs/sync_tasks_overhead.c

@@ -117,7 +117,7 @@ int main(int argc, char **argv)
                         fprintf(f, "%s\t%f\n", bench_id, timing/1000000);
                         fclose(f);
 
-                        sprintf(file, "%s/sync_tasks_overhead_per_task.dat", output_dir);
+                        snprintf(file, 1024, "%s/sync_tasks_overhead_per_task.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, timing/ntasks);
                         fclose(f);

+ 7 - 7
tests/microbenchs/tasks_overhead.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2011, 2013-2014, 2016  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2015  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2015, 2016  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
@@ -187,32 +187,32 @@ int main(int argc, char **argv)
                         char file[1024];
                         FILE *f;
 
-                        sprintf(file, "%s/tasks_overhead_total_submit.dat", output_dir);
+                        snprintf(file, 1024, "%s/tasks_overhead_total_submit.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, timing_submit/1000000);
                         fclose(f);
 
-                        sprintf(file, "%s/tasks_overhead_per_task_submit.dat", output_dir);
+                        snprintf(file, 1024, "%s/tasks_overhead_per_task_submit.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, timing_submit/ntasks);
                         fclose(f);
 
-                        sprintf(file, "%s/tasks_overhead_total_execution.dat", output_dir);
+                        snprintf(file, 1024, "%s/tasks_overhead_total_execution.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, timing_exec/1000000);
                         fclose(f);
 
-                        sprintf(file, "%s/tasks_overhead_per_task_execution.dat", output_dir);
+                        snprintf(file, 1024, "%s/tasks_overhead_per_task_execution.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, timing_exec/ntasks);
                         fclose(f);
 
-                        sprintf(file, "%s/tasks_overhead_total_submit_execution.dat", output_dir);
+                        snprintf(file, 1024, "%s/tasks_overhead_total_submit_execution.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, (timing_submit+timing_exec)/1000000);
                         fclose(f);
 
-                        sprintf(file, "%s/tasks_overhead_per_task_submit_execution.dat", output_dir);
+                        snprintf(file, 1024, "%s/tasks_overhead_per_task_submit_execution.dat", output_dir);
                         f = fopen(file, "a");
                         fprintf(f, "%s\t%f\n", bench_id, (timing_submit+timing_exec)/ntasks);
                         fclose(f);

+ 1 - 0
tests/sched_policies/simple_cpu_gpu_sched.c

@@ -114,6 +114,7 @@ init_perfmodels_gpu(int gpu_type)
 							       gpu_type, starpu_worker_get_devid(worker_gpu_ids[worker_gpu]), 1,
 							       -1);
 	}
+	free(worker_gpu_ids);
 }
 
 static void

+ 2 - 2
tools/starpu_lp2paje.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2011, 2013-2014  Université de Bordeaux
- * Copyright (C) 2014, 2015                  CNRS
+ * Copyright (C) 2014, 2015, 2016                  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
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
 		fprintf(stderr, "\n");
 		exit(EXIT_SUCCESS);
 	}
-	scanf("Suboptimal solution\n");
+	assert(scanf("Suboptimal solution\n") == 0);
 	assert(scanf("\nValue of objective function: %lf\n", &tmax) == 1);
 
 	assert(scanf("Actual values of the variables:\n") == 0);