From 9b63e94f825cee3d2dc4ca0b8156102cc84bb4c5 Mon Sep 17 00:00:00 2001 From: Magnus Lundborg Date: Wed, 4 Dec 2013 09:21:47 +0100 Subject: Do not require pointer to NULL. diff --git a/include/tng_io.h b/include/tng_io.h index 7be9c12..7ae8967 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -4668,7 +4668,8 @@ tng_function_status DECLSPECDLLEXPORT tng_util_frame_current_compression_get * data for next_frame. * @param data_block_ids_in_next_frame is set to an array (of length * n_data_blocks_in_next_frame) that lists the data block IDs with data for - * next_frame. The array is created by this function allocated. + * next_frame. It must be pointing at NULL or previously allocated memory. + * Memory for the array is allocated by this function. * The memory must be freed by the client afterwards or * there will be a memory leak. * @pre \code tng_data != 0 \endcode The trajectory container (tng_data) @@ -4677,7 +4678,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_frame_current_compression_get * be NULL. * @pre \code n_data_blocks_in_next_frame != 0 \endcode The pointer to * n_data_blocks_in_next_frame must not be NULL. - * @pre \code *data_block_ids_in_next_frame == 0 \endcode The pointer to the + * @pre \code *data_block_ids_in_next_frame != 0 \endcode The pointer to the * list of data block IDs must not be NULL. * @pre \code n_requested_data_block_ids == 0 || requested_data_block_ids != 0 \endcode * If the number of requested data blocks != 0 then the array of data block IDs must not be NULL. diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 908f471..6bbc1c5 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -17955,12 +17955,23 @@ tng_function_status DECLSPECDLLEXPORT tng_util_trajectory_next_frame_present_dat TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); TNG_ASSERT(next_frame, "TNG library: The pointer to the next frame must not be NULL."); TNG_ASSERT(n_data_blocks_in_next_frame, "TNG library: The pointer to n_data_blocks_in_next_frame must not be NULL."); - TNG_ASSERT(*data_block_ids_in_next_frame == 0, "TNG library: The pointer to the list of data block IDs must be NULL."); + TNG_ASSERT(data_block_ids_in_next_frame, "TNG library: The pointer to the list of data block IDs must not be NULL."); if(n_requested_data_block_ids) { TNG_ASSERT(requested_data_block_ids, "TNG library: If the number of requested data blocks is > 0 then the array of data block IDs must not be NULL."); - *data_block_ids_in_next_frame = malloc(sizeof(int64_t) * n_requested_data_block_ids); + size = sizeof(int64_t) * n_requested_data_block_ids; + temp = realloc(*data_block_ids_in_next_frame, size); + if(!temp) + { + printf("TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n", + sizeof(int64_t) * (*n_data_blocks_in_next_frame), + __FILE__, __LINE__); + free(*data_block_ids_in_next_frame); + *data_block_ids_in_next_frame = 0; + return(TNG_CRITICAL); + } + *data_block_ids_in_next_frame = temp; } frame_set = &tng_data->current_trajectory_frame_set; -- cgit v0.10.1