Browse Source

fix bugs detected by coverity

Nathalie Furmento 9 years ago
parent
commit
37529e0c2a

+ 2 - 2
examples/basic_examples/block_opencl.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010, 2011  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
@@ -42,7 +42,7 @@ void opencl_codelet(void *descr[], void *_args)
         int ldz = (int) STARPU_BLOCK_GET_LDZ(descr[0]);
         float *multiplier = (float *)_args;
 
-        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_code, "block", devid);

+ 5 - 1
examples/heat/dw_factolu.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2009-2015  Université de Bordeaux
  * Copyright (C) 2010  Mehdi Juhoor <mjuhoor@gmail.com>
- * Copyright (C) 2010, 2011, 2012  CNRS
+ * Copyright (C) 2010, 2011, 2012, 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
@@ -546,6 +546,8 @@ void dw_callback_codelet_update_u11(void *argcb)
 			ret = starpu_task_submit(task21);
 			STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
 		}
+
+		free(remaining);
 	}
 }
 
@@ -636,6 +638,8 @@ void dw_callback_codelet_update_u12_21(void *argcb)
 				STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
 			}
 		}
+
+		free(remaining);
 	}
 }
 

+ 2 - 2
examples/heat/dw_factolu_grain.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2009, 2010-2011, 2014-2016  Université de Bordeaux
  * Copyright (C) 2010  Mehdi Juhoor <mjuhoor@gmail.com>
- * Copyright (C) 2010, 2011, 2012  CNRS
+ * Copyright (C) 2010, 2011, 2012, 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
@@ -316,7 +316,7 @@ static void dw_factoLU_grain_inner(float *matA, unsigned size, unsigned inner_si
 		 */
 
 		unsigned ndeps_tags = (nblocks - maxk)*(nblocks - maxk);
-		starpu_tag_t *tag_array = malloc(ndeps_tags*sizeof(starpu_tag_t));
+		starpu_tag_t *tag_array = calloc(ndeps_tags, sizeof(starpu_tag_t));
 		STARPU_ASSERT(tag_array);
 
 		unsigned ind = 0;

+ 4 - 4
examples/ppm_downscaler/yuv_downscaler.c

@@ -43,13 +43,13 @@ void parse_args(int argc, char **argv)
 {
 	if (argc == 3)
 	{
-		strcpy(filename_in, argv[1]);
-		strcpy(filename_out, argv[2]);
+		strncpy(filename_in, argv[1], 1024);
+		strncpy(filename_out, argv[2], 1024);
 	}
 	else
 	{
-		sprintf(filename_in, "%s/examples/ppm_downscaler/%s", STARPU_BUILD_DIR, filename_in_default);
-		sprintf(filename_out, "%s/examples/ppm_downscaler/%s", STARPU_BUILD_DIR, filename_out_default);
+		snprintf(filename_in, 1024, "%s/examples/ppm_downscaler/%s", STARPU_BUILD_DIR, filename_in_default);
+		snprintf(filename_out, 1024, "%s/examples/ppm_downscaler/%s", STARPU_BUILD_DIR, filename_out_default);
 	}
 }
 

+ 7 - 9
mpi/tests/mpi_earlyrecv2_sync.c

@@ -20,7 +20,7 @@
 #include <unistd.h>
 #include <interface/complex_interface.h>
 
-#define NB 4
+#define NB 6
 
 typedef void (*check_func)(starpu_data_handle_t handle, int i, int rank, int *error);
 
@@ -35,20 +35,22 @@ int exchange(int rank, starpu_data_handle_t *handles, check_func func)
 
 	if (rank%2)
 	{
-#if 1
 		starpu_mpi_issend(handles[0], &req[0], other_rank, 0, MPI_COMM_WORLD);
 		starpu_mpi_isend(handles[NB-1], &req[NB-1], other_rank, NB-1, MPI_COMM_WORLD);
 		starpu_mpi_issend(handles[NB-2], &req[NB-2], other_rank, NB-2, MPI_COMM_WORLD);
 
 		for(i=1 ; i<NB-2 ; i++)
-#else
-		for(i=0 ; i<NB ; i++)
-#endif
 		{
 			if (i%2)
+			{
+				FPRINTF_MPI(stderr, "iSsending value %d\n", i);
 				starpu_mpi_issend(handles[i], &req[i], other_rank, i, MPI_COMM_WORLD);
+			}
 			else
+			{
+				FPRINTF_MPI(stderr, "isending value %d\n", i);
 				starpu_mpi_isend(handles[i], &req[i], other_rank, i, MPI_COMM_WORLD);
+			}
 		}
 		for(i=0 ; i<NB ; i++)
 		{
@@ -57,7 +59,6 @@ int exchange(int rank, starpu_data_handle_t *handles, check_func func)
 	}
 	else
 	{
-#if 1
 		starpu_mpi_irecv(handles[0], &req[0], other_rank, 0, MPI_COMM_WORLD);
 		STARPU_ASSERT(req[0] != NULL);
 		starpu_mpi_irecv(handles[1], &req[1], other_rank, 1, MPI_COMM_WORLD);
@@ -66,9 +67,6 @@ int exchange(int rank, starpu_data_handle_t *handles, check_func func)
 		// We sleep to make sure that the data for the tag 8 and the tag 9 will be received before the recv are posted
 		usleep(2000000);
 		for(i=2 ; i<NB ; i++)
-#else
-		for(i=0 ; i<NB ; i++)
-#endif
 		{
 			starpu_mpi_irecv(handles[i], &req[i], other_rank, i, MPI_COMM_WORLD);
 			STARPU_ASSERT(req[i] != NULL);

+ 15 - 1
src/top/starpu_top_connection.c

@@ -128,8 +128,17 @@ void _starpu_top_communications_threads_launcher(void)
 		exit(EXIT_FAILURE);
    	}
   	int sock=socket(ans->ai_family, ans->ai_socktype, ans->ai_protocol);
+	if (sock < 0)
+	{
+		perror("socket");
+		exit(EXIT_FAILURE);
+	}
 	int optval = 1;
-	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &optval, sizeof(optval));
+	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &optval, sizeof(optval)) == -1)
+	{
+		perror("setsockopt");
+		exit(EXIT_FAILURE);
+	}
 
 	if (bind(sock, ans->ai_addr, ans->ai_addrlen) < 0)
 	{
@@ -155,6 +164,11 @@ void _starpu_top_communications_threads_launcher(void)
 	}
 
 	starpu_top_socket_fd=dup(starpu_top_socket_fd);
+	if (starpu_top_socket_fd == -1)
+	{
+		perror("dup");
+		exit(EXIT_FAILURE);
+	}
 
 	if ((starpu_top_socket_fd_write=fdopen(starpu_top_socket_fd, "w")) == NULL)
 	{

+ 13 - 13
src/top/starpu_top_message_queue.c

@@ -29,6 +29,13 @@ struct _starpu_top_message_queue*  _starpu_top_mt = NULL;
 struct _starpu_top_message_queue* _starpu_top_message_add(struct _starpu_top_message_queue* s,
 							char* msg)
 {
+	if( NULL == s )
+	{
+		printf("Queue not initialized\n");
+		free(msg);
+		return s;
+	}
+
 	struct _starpu_top_message_queue_item* p = (struct _starpu_top_message_queue_item *) malloc( 1 * sizeof(*p) );
 	STARPU_PTHREAD_MUTEX_LOCK(&(s->mutex));
 	if( NULL == p )
@@ -42,15 +49,7 @@ struct _starpu_top_message_queue* _starpu_top_message_add(struct _starpu_top_mes
 	p->message = msg;
 	p->next = NULL;
 
-	if( NULL == s )
-	{
-		printf("Queue not initialized\n");
-		free(msg);
-		free(p);
-		STARPU_PTHREAD_MUTEX_UNLOCK(&(s->mutex));
-		return s;
-	}
-	else if( NULL == s->head && NULL == s->tail )
+	if( NULL == s->head && NULL == s->tail )
 	{
 		/* printf("Empty list, adding p->num: %d\n\n", p->num);  */
 		sem_post(&(s->semaphore));
@@ -72,15 +71,16 @@ struct _starpu_top_message_queue* _starpu_top_message_add(struct _starpu_top_mes
 //this is a queue and it is FIFO, so we will always remove the first element
 char* _starpu_top_message_remove(struct _starpu_top_message_queue* s)
 {
-	sem_wait(&(s->semaphore));
-	struct _starpu_top_message_queue_item* h = NULL;
-	struct _starpu_top_message_queue_item* p = NULL;
-
 	if( NULL == s )
 	{
 		printf("List is null\n");
 		return NULL;
 	}
+
+	sem_wait(&(s->semaphore));
+	struct _starpu_top_message_queue_item* h = NULL;
+	struct _starpu_top_message_queue_item* p = NULL;
+
 	STARPU_PTHREAD_MUTEX_LOCK(&(s->mutex));
 	h = s->head;
 	p = h->next;

+ 5 - 0
tests/disk/disk_pack.c

@@ -136,6 +136,9 @@ int dotest(struct starpu_disk_ops *ops, char *base)
 	fclose(f);
 
 	int descriptor = open(path_file_start, O_RDWR);
+	if (descriptor < 0)
+		goto enoent2;
+
 #ifdef STARPU_HAVE_WINDOWS
 	_commit(descriptor);
 #else
@@ -155,6 +158,8 @@ int dotest(struct starpu_disk_ops *ops, char *base)
 	fclose(f);
 
         descriptor = open(path_file_end, O_RDWR);
+	if (descriptor < 0)
+		goto enoent2;
 #ifdef STARPU_HAVE_WINDOWS
         _commit(descriptor);
 #else