avoid segfault when num_pixels is not an even multiple of task_size

git-svn-id: svn://anubis/gvsu@346 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-12-08 23:29:48 +00:00
parent f85f20be57
commit 7a87e395c4

View File

@ -341,7 +341,11 @@ void draw(int rank, int world_size, int nprocs, int width, int height,
MPI_Send(&done_val, 1, MPI_INT, MPI_Send(&done_val, 1, MPI_INT,
mpi_status.MPI_SOURCE, 0, MPI_COMM_WORLD); mpi_status.MPI_SOURCE, 0, MPI_COMM_WORLD);
} }
memcpy(pixels + taskVals[0], taskVals + 1, task_size * sizeof(int)); int num_to_copy = task_size;
if (taskVals[0] + num_to_copy > num_pixels)
num_to_copy = num_pixels - taskVals[0];
memcpy(pixels + taskVals[0], taskVals + 1,
num_to_copy * sizeof(int));
} }
} }
else else