summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Lundborg <lundborg.magnus@gmail.com>2013-11-28 10:40:06 (GMT)
committerMagnus Lundborg <lundborg.magnus@gmail.com>2013-11-28 10:40:06 (GMT)
commitc61e697a14c4729a20a93e7aaf4b8e6d014587f8 (patch)
treeb27af48aebb8b0eedd14593f8c5da07143fbe87f /src
parent614a6a93a8ae6e1f1f90b6506a5772f036508caf (diff)
Final fixing of mol system copying?
Diffstat (limited to 'src')
-rw-r--r--src/lib/tng_io.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index 857ed57..23b1620 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -7335,24 +7335,25 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_system_copy(tng_trajectory_t
tng_molecule_destroy(tng_data_dest, molecule);
}
- tng_data_dest->n_molecules = tng_data_src->n_molecules;
+ tng_data_dest->n_molecules = 0;
- free(tng_data_dest->molecules);
-
- tng_data_dest->molecules = malloc(sizeof(struct tng_molecule) * tng_data_dest->n_molecules);
- if(!tng_data_dest->molecules)
+ molecule_temp = realloc(tng_data_dest->molecules,
+ sizeof(struct tng_molecule) * tng_data_src->n_molecules);
+ if(!molecule_temp)
{
printf("TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
- sizeof(struct tng_molecule) * tng_data_dest->n_molecules,
+ sizeof(struct tng_molecule) * tng_data_src->n_molecules,
__FILE__, __LINE__);
+ free(tng_data_dest->molecules);
+ tng_data_dest->molecules = 0;
return(TNG_CRITICAL);
}
list_temp = realloc(tng_data_dest->molecule_cnt_list,
- sizeof(int64_t) * tng_data_dest->n_molecules);
+ sizeof(int64_t) * tng_data_src->n_molecules);
if(!list_temp)
{
printf("TNG library: Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
- sizeof(int64_t) * tng_data_dest->n_molecules,
+ sizeof(int64_t) * tng_data_src->n_molecules,
__FILE__, __LINE__);
free(tng_data_dest->molecule_cnt_list);
tng_data_dest->molecule_cnt_list = 0;
@@ -7360,9 +7361,10 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_system_copy(tng_trajectory_t
return(TNG_CRITICAL);
}
+ tng_data_dest->molecules = molecule_temp;
tng_data_dest->molecule_cnt_list = list_temp;
- for(i = 0; i < tng_data_dest->n_molecules; i++)
+ for(i = 0; i < tng_data_src->n_molecules; i++)
{
molecule = &tng_data_src->molecules[i];
stat = tng_molecule_w_id_add(tng_data_dest, molecule->name, molecule->id,
contact: Jan Huwald // Impressum