if (!is_insert)
ig3 = IntGroupNew();
for (j = 0; (up = ParameterGetUnionParFromTypeAndIndex(mol->par, i, j)) != NULL; j++) {
- usave = *up;
+ ParameterCopyOneWithType(&usave, up, i); /* Don't say usave = *up */
if (ParameterRenumberAtoms(i, up, old_natoms, ip) && !is_insert) {
IntGroupAdd(ig3, j, 1); /* This parameter is to be restored on undo */
AssignArray(&upary, &count_upary, sizeof(UnionPar), count_upary, &usave);
ip = (Int *)malloc(sizeof(Int) * 2 * result);
if (ip == NULL)
return -4;
- memmove(ip, mol->bonds - result * 2, sizeof(Int) * 2 * result);
+ memmove(ip, mol->bonds + (mol->nbonds - result) * 2, sizeof(Int) * 2 * result);
act2 = MolActionNew(gMolActionDeleteBonds, result * 2, ip);
free(ip);
needsRebuildMDArena = 1;
}
}
+void
+ParameterCopyOneWithType(UnionPar *dst, const UnionPar *src, int type)
+{
+ int size = ParameterGetSizeForType(type);
+ memmove(dst, src, size);
+}
+
UnionPar *
ParameterRefGetPar(ParameterRef *pref)
{
int ParameterDelete(Parameter *par, Int type, UnionPar *up, struct IntGroup *where);
int ParameterCopy(Parameter *par, Int type, UnionPar *up, struct IntGroup *where);
+/* Caution! When up is a UnionPar pointer given by ParameterGetUnionParFromTypeAndIndex() etc and
+ u is a UnionPar variable, u = *up will cause Bad Address exception, if up is at the last
+ of the allocated array and sizeof(UnionPar) is larger than the size of actual parameter record.
+ This copy function does take care of such case. */
+void ParameterCopyOneWithType(UnionPar *dst, const UnionPar *src, int type);
+
int ParameterRenumberAtoms(Int type, UnionPar *up, Int oldnatoms, const Int *old2new);
int ParameterDoesContainAtom(Int type, UnionPar *up, UInt atom_type, Int options);