Browse Source

fix bugs detected by coverity

Nathalie Furmento 8 years ago
parent
commit
3cdc863cb4

+ 2 - 2
examples/basic_examples/variable_kernels_opencl.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2012  CNRS
+ * Copyright (C) 2010, 2012, 2016  CNRS
  * Copyright (C) 2011  Université de Bordeaux
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@ void opencl_codelet(void *descr[], void *_args)
 	cl_event event;
 	int id, devid, err;
 
-        id = starpu_worker_get_id();
+        id = starpu_worker_get_id_check();
         devid = starpu_worker_get_devid(id);
 
 	err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_program, "variable", devid);

+ 1 - 1
examples/cg/cg_kernels.c

@@ -478,7 +478,7 @@ int gemv_kernel(starpu_data_handle_t v1,
 						 STARPU_R,	starpu_data_get_sub_data(v2, 1, b1),
 						 STARPU_VALUE,	&one,	sizeof(one),
 						 STARPU_VALUE,	&p2,	sizeof(p2),
-						 STARPU_TAG_ONLY, (starpu_tag_t) (b2 * nblocks + b1),
+						 STARPU_TAG_ONLY, ((starpu_tag_t)b2) * nblocks + b1,
 						 0);
 			STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
 		}

+ 5 - 2
examples/filters/shadow2d.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2012-2014  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
@@ -121,6 +121,8 @@ void cpu_func(void *buffers[], void *cl_arg)
 #ifdef STARPU_USE_CUDA
 void cuda_func(void *buffers[], void *cl_arg)
 {
+	cudaError_t cures;
+
         /* length of the shadowed source matrix */
         unsigned ld = STARPU_MATRIX_GET_LD(buffers[0]);
         unsigned n = STARPU_MATRIX_GET_NX(buffers[0]);
@@ -138,7 +140,8 @@ void cuda_func(void *buffers[], void *cl_arg)
 	/* If things go right, sizes should match */
 	STARPU_ASSERT(n == n2);
 	STARPU_ASSERT(m == m2);
-	cudaMemcpy2DAsync(val2, ld2*sizeof(*val2), val, ld*sizeof(*val), n*sizeof(*val), m, cudaMemcpyDeviceToDevice, starpu_cuda_get_local_stream());
+	cures = cudaMemcpy2DAsync(val2, ld2*sizeof(*val2), val, ld*sizeof(*val), n*sizeof(*val), m, cudaMemcpyDeviceToDevice, starpu_cuda_get_local_stream());
+        if (STARPU_UNLIKELY(cures)) STARPU_CUDA_REPORT_ERROR(cures);
 }
 #endif
 

+ 2 - 2
examples/heat/dw_sparse_cg.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009, 2010, 2011, 2015  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013  CNRS
+ * Copyright (C) 2010, 2011, 2012, 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
@@ -204,7 +204,7 @@ void launch_new_cg_iteration(struct cg_problem *problem)
 
 	unsigned iter = problem->i;
 
-	unsigned long long maskiter = (iter*1024);
+	unsigned long long maskiter = ((unsigned long long)iter*1024);
 
 	/* q = A d */
 	struct starpu_task *task4 = create_task(maskiter | 4UL);

+ 1 - 1
examples/mandelbrot/mandelbrot.c

@@ -555,7 +555,7 @@ int main(int argc, char **argv)
 						 STARPU_VALUE, &stepY, sizeof(stepY),
 						 STARPU_W, block_handles[iby],
 						 STARPU_VALUE, &pcnt, sizeof(int *),
-						 STARPU_TAG_ONLY, (starpu_tag_t) (niter*nblocks + iby),
+						 STARPU_TAG_ONLY, ((starpu_tag_t)niter)*nblocks + iby,
 						 0);
 			STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
 		}

+ 7 - 5
examples/ppm_downscaler/yuv_downscaler.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2010-2011, 2013-2015  Université de Bordeaux
  * Copyright (C) 2010  Mehdi Juhoor <mjuhoor@gmail.com>
- * Copyright (C) 2010, 2011, 2012, 2013  CNRS
+ * Copyright (C) 2010, 2011, 2012, 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
@@ -115,17 +115,18 @@ int main(int argc, char **argv)
 
 	assert(HEIGHT % (2*BLOCK_HEIGHT) == 0);
 	assert(HEIGHT % FACTOR == 0);
-	
+
 	parse_args(argc, argv);
 
 /*	fprintf(stderr, "Reading input file ...\n"); */
 
 	/* how many frames ? */
 	struct stat stbuf;
-	stat(filename_in, &stbuf);
+	ret = stat(filename_in, &stbuf);
+	assert(ret);
 	size_t filesize = stbuf.st_size;
 
-	unsigned nframes = filesize/FRAMESIZE; 
+	unsigned nframes = filesize/FRAMESIZE;
 
 /*	fprintf(stderr, "filesize %lx (FRAME SIZE %lx NEW SIZE %lx); nframes %d\n", filesize, FRAMESIZE, NEW_FRAMESIZE, nframes); */
 	assert((filesize % sizeof(struct yuv_frame)) == 0);
@@ -145,7 +146,8 @@ int main(int argc, char **argv)
 	FILE *f_out = fopen(filename_out, "w+");
 	assert(f_out);
 
-	fread(yuv_in_buffer, FRAMESIZE, nframes, f_in);
+	ret = fread(yuv_in_buffer, FRAMESIZE, nframes, f_in);
+	assert(ret == nframes);
 
 	starpu_data_handle_t *frame_y_handle = (starpu_data_handle_t *)  calloc(nframes, sizeof(starpu_data_handle_t));
 	starpu_data_handle_t *frame_u_handle = (starpu_data_handle_t *)  calloc(nframes, sizeof(starpu_data_handle_t));

+ 29 - 21
sc_hypervisor/src/hypervisor_policies/perf_count_policy.c

@@ -51,7 +51,8 @@ long long total_instr[STARPU_NMAX_SCHED_CTXS];
 /* long long total_branch_instr[STARPU_NMAX_SCHED_CTXS]; */
 long long total_fps[STARPU_NMAX_SCHED_CTXS];
 
-struct read_format {
+struct read_format
+{
 	uint64_t value;         /* The value of the event */
 	uint64_t time_enabled;  /* if PERF_FORMAT_TOTAL_TIME_ENABLED */
 	uint64_t time_running;  /* if PERF_FORMAT_TOTAL_TIME_RUNNING */
@@ -67,14 +68,17 @@ static long perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu,
 
 void print_results_for_worker(int workerid, unsigned sched_ctx, struct starpu_task *task)
 {
+	ssize_t rread;
 	long long  instr, /*cycles, cache_misses, cache_refs, branch_instr,*/ fps;
-	read(fd_instr[workerid], &instr, sizeof(instr));
+	rread = read(fd_instr[workerid], &instr, sizeof(instr));
+	assert(rread == sizeof(instr));
 	/* read(fd_cycles[workerid], &cycles, sizeof(long long)); */
 	/* read(fd_cache_misses[workerid], &cache_misses, sizeof(long long)); */
 	/* read(fd_cache_refs[workerid], &cache_refs, sizeof(long long)); */
 	/* read(fd_branch_instr[workerid], &branch_instr, sizeof(long long)); */
-	read(fd_fps[workerid], &fps, sizeof(long long));
-	
+	rread = read(fd_fps[workerid], &fps, sizeof(long long));
+	assert(rread == sizeof(long long));
+
 	total_instr[sched_ctx] += instr;
 	/* total_cycles[sched_ctx] += cycles; */
 	/* total_cache_misses[sched_ctx] += cache_misses; */
@@ -100,7 +104,7 @@ void print_results_for_ctx(unsigned sched_ctx, struct starpu_task *task)
         /* long long curr_total_cache_refs = 0; */
         /* long long curr_total_branch_instr = 0; */
         long long curr_total_fps = 0;
-	
+
 	struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
 
 	struct starpu_sched_ctx_iterator it;
@@ -109,16 +113,20 @@ void print_results_for_ctx(unsigned sched_ctx, struct starpu_task *task)
 	workers->init_iterator(workers, &it);
         while(workers->has_next(workers, &it))
 	{
+		ssize_t rread;
+
 		workerid = workers->get_next(workers, &it);
                 // Read event counter value
                 struct read_format instr, /*cycles, cache_misses, cache_refs, branch_instr,*/ fps;
-                read(fd_instr[workerid], &instr, sizeof(struct read_format));  
+                rread = read(fd_instr[workerid], &instr, sizeof(struct read_format));
+		assert(rread==sizeof(struct read_format));
 		/* read(fd_cycles[workerid], &cycles, sizeof(long long));  */
                 /* read(fd_cache_misses[workerid], &cache_misses, sizeof(long long)); */
 		/* read(fd_cache_refs[workerid], &cache_refs, sizeof(long long));   */
 		/* read(fd_branch_instr[workerid], &branch_instr, sizeof(long long));  */
-		read(fd_fps[workerid], &fps, sizeof(struct read_format)); 
-		
+		rread = read(fd_fps[workerid], &fps, sizeof(struct read_format));
+		assert(rread == sizeof(struct read_format));
+
 		curr_total_instr += (instr.time_enabled != 0 && instr.time_running !=0) ? instr.value * instr.time_enabled/instr.time_running : instr.value;
 		printf("w%d instr time enabled %"PRIu64" time running %"PRIu64" \n", workerid, instr.time_enabled, instr.time_running);
 
@@ -142,7 +150,7 @@ void print_results_for_ctx(unsigned sched_ctx, struct starpu_task *task)
         printf("%d: Fps %lf k curr fps %lf k\n",  sched_ctx,
 	       (double)total_fps[sched_ctx]/1000,
 	       (double)curr_total_fps/1000);
-    
+
 	printf("%d: Task Flops %lf k %s \n", sched_ctx, task->flops/1000, (task->cl && task->cl->model) ? task->cl->model->symbol : "task null");
         printf("-------------------------------------------\n");
 }
@@ -153,11 +161,11 @@ void config_event(struct perf_event_attr *event, unsigned with_time, uint64_t ev
 	event->type = event_type;
 	event->size = sizeof(struct perf_event_attr);
 	event->config = config_type;
-	event->disabled = 1;        // Event is initially disabled                    
+	event->disabled = 1;        // Event is initially disabled
 	event->exclude_kernel = 1;  // excluding events that happen in the kernel space
 	if(with_time)
 	{
-	     /* if the PMU is multiplexing several events we measure the time spent to actually measure this event (time_running) 
+	     /* if the PMU is multiplexing several events we measure the time spent to actually measure this event (time_running)
 		and compare it to the one expected is did, thus we compute the precision of the counter*/
 		event->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED|PERF_FORMAT_TOTAL_TIME_RUNNING;
 	}
@@ -208,19 +216,19 @@ void start_monitoring_all_events_for_worker(int workerid)
 {
 	ioctl(fd_instr[workerid], PERF_EVENT_IOC_RESET, 0);
 	ioctl(fd_instr[workerid], PERF_EVENT_IOC_ENABLE, 0);
-	
+
 	/* ioctl(fd_cycles[workerid], PERF_EVENT_IOC_RESET, 0); */
 	/* ioctl(fd_cycles[workerid], PERF_EVENT_IOC_ENABLE, 0); */
-	
+
 	/* ioctl(fd_cache_misses[workerid], PERF_EVENT_IOC_RESET, 0); */
 	/* ioctl(fd_cache_misses[workerid], PERF_EVENT_IOC_ENABLE, 0); */
-	
+
 	/* ioctl(fd_cache_refs[workerid], PERF_EVENT_IOC_RESET, 0); */
 	/* ioctl(fd_cache_refs[workerid], PERF_EVENT_IOC_ENABLE, 0); */
 
 	/* ioctl(fd_branch_instr[workerid], PERF_EVENT_IOC_RESET, 0); */
 	/* ioctl(fd_branch_instr[workerid], PERF_EVENT_IOC_ENABLE, 0); */
-	
+
 	ioctl(fd_fps[workerid], PERF_EVENT_IOC_RESET, 0);
 	ioctl(fd_fps[workerid], PERF_EVENT_IOC_ENABLE, 0);
 }
@@ -240,7 +248,7 @@ void perf_count_handle_idle_end(unsigned sched_ctx, int worker)
 	unsigned has_starpu_scheduler;
 	unsigned has_awake_workers;
 	has_starpu_scheduler = starpu_sched_ctx_has_starpu_scheduler(sched_ctx, &has_awake_workers);
-       
+
 	if(!has_starpu_scheduler && !has_awake_workers)
 	{
 		struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
@@ -269,7 +277,7 @@ void perf_count_handle_idle_end(unsigned sched_ctx, int worker)
 }
 
 void perf_count_handle_poped_task(unsigned sched_ctx, int worker,
-				  struct starpu_task *task, 
+				  struct starpu_task *task,
 				  __attribute__((unused))uint32_t footprint)
 {
 	unsigned has_starpu_scheduler;
@@ -318,9 +326,9 @@ void perf_count_init_worker(int workerid, unsigned sched_ctx)
 void perf_count_start_ctx(unsigned sched_ctx)
 {
 	struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
-	
+
 	struct starpu_sched_ctx_iterator it;
-	
+
 	int workerid;
 	workers->init_iterator(workers, &it);
 	while(workers->has_next(workers, &it))
@@ -333,9 +341,9 @@ void perf_count_start_ctx(unsigned sched_ctx)
 void perf_count_end_ctx(unsigned sched_ctx)
 {
 	struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
-	
+
 	struct starpu_sched_ctx_iterator it;
-	
+
 	int workerid;
 	workers->init_iterator(workers, &it);
 	while(workers->has_next(workers, &it))

+ 1 - 1
sc_hypervisor/src/policies_utils/lp_tools.c

@@ -335,7 +335,7 @@ void sc_hypervisor_lp_round_double_to_int(int ns, int nw, double res[ns][nw], in
 	int s, w;
 	double left_res[nw];
 	for(w = 0; w < nw; w++)
-		left_res[nw] = 0.0;
+		left_res[w] = 0.0;
 	for(s = 0; s < ns; s++)
 	{
 		for(w = 0; w < nw; w++)

+ 1 - 1
sc_hypervisor/src/sc_hypervisor.c

@@ -1357,7 +1357,7 @@ static void _update_counters_hierarchically(int worker, unsigned sched_ctx, doub
 static void notify_post_exec_task(struct starpu_task *task, size_t data_size, uint32_t footprint, int task_tag, double flops)
 {
 	unsigned sched_ctx = task->sched_ctx;
-	int worker = starpu_worker_get_id();
+	int worker = starpu_worker_get_id_check();
 
 	if(hypervisor.sched_ctx_w[sched_ctx].exec_start_time[worker] != 0.0)
 	{

+ 2 - 2
src/common/fxt.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2015  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 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
@@ -83,7 +83,7 @@ static void _starpu_profile_set_tracefile(void *last, ...)
 	     fxt_prefix = "/tmp/";
 
 	va_start(vl, last);
-	vsprintf(_STARPU_PROF_FILE_USER, fxt_prefix, vl);
+	vnsprintf(_STARPU_PROF_FILE_USER, 128, fxt_prefix, vl);
 	va_end(vl);
 
 	user = starpu_getenv("USER");

+ 1 - 1
src/datawizard/memalloc.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2016  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 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