Molecular Modeling Software
リビジョン | cbbf234aed88e1642c7fa97a01131a455545dfbc (tree) |
---|---|
日時 | 2010-05-07 00:13:59 |
作者 | toshinagata1964 <toshinagata1964@a2be...> |
コミッター | toshinagata1964 |
Some parameter editing caused segmentation fault; fixed.
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@45 a2be9bc6-48de-4e38-9406-05402d4bc13c
@@ -559,7 +559,7 @@ sMolActionUpdateSelectionAndParameterNumbering(Molecule *mol, const IntGroup *ig | ||
559 | 559 | if (!is_insert) |
560 | 560 | ig3 = IntGroupNew(); |
561 | 561 | for (j = 0; (up = ParameterGetUnionParFromTypeAndIndex(mol->par, i, j)) != NULL; j++) { |
562 | - usave = *up; | |
562 | + ParameterCopyOneWithType(&usave, up, i); /* Don't say usave = *up */ | |
563 | 563 | if (ParameterRenumberAtoms(i, up, old_natoms, ip) && !is_insert) { |
564 | 564 | IntGroupAdd(ig3, j, 1); /* This parameter is to be restored on undo */ |
565 | 565 | AssignArray(&upary, &count_upary, sizeof(UnionPar), count_upary, &usave); |
@@ -780,7 +780,7 @@ MolActionPerform(Molecule *mol, MolAction *action) | ||
780 | 780 | ip = (Int *)malloc(sizeof(Int) * 2 * result); |
781 | 781 | if (ip == NULL) |
782 | 782 | return -4; |
783 | - memmove(ip, mol->bonds - result * 2, sizeof(Int) * 2 * result); | |
783 | + memmove(ip, mol->bonds + (mol->nbonds - result) * 2, sizeof(Int) * 2 * result); | |
784 | 784 | act2 = MolActionNew(gMolActionDeleteBonds, result * 2, ip); |
785 | 785 | free(ip); |
786 | 786 | needsRebuildMDArena = 1; |
@@ -283,6 +283,13 @@ ParameterGetSizeForType(int type) | ||
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | +void | |
287 | +ParameterCopyOneWithType(UnionPar *dst, const UnionPar *src, int type) | |
288 | +{ | |
289 | + int size = ParameterGetSizeForType(type); | |
290 | + memmove(dst, src, size); | |
291 | +} | |
292 | + | |
286 | 293 | UnionPar * |
287 | 294 | ParameterRefGetPar(ParameterRef *pref) |
288 | 295 | { |
@@ -202,6 +202,12 @@ int ParameterInsert(Parameter *par, Int type, const UnionPar *up, struct IntGrou | ||
202 | 202 | int ParameterDelete(Parameter *par, Int type, UnionPar *up, struct IntGroup *where); |
203 | 203 | int ParameterCopy(Parameter *par, Int type, UnionPar *up, struct IntGroup *where); |
204 | 204 | |
205 | +/* Caution! When up is a UnionPar pointer given by ParameterGetUnionParFromTypeAndIndex() etc and | |
206 | + u is a UnionPar variable, u = *up will cause Bad Address exception, if up is at the last | |
207 | + of the allocated array and sizeof(UnionPar) is larger than the size of actual parameter record. | |
208 | + This copy function does take care of such case. */ | |
209 | +void ParameterCopyOneWithType(UnionPar *dst, const UnionPar *src, int type); | |
210 | + | |
205 | 211 | int ParameterRenumberAtoms(Int type, UnionPar *up, Int oldnatoms, const Int *old2new); |
206 | 212 | int ParameterDoesContainAtom(Int type, UnionPar *up, UInt atom_type, Int options); |
207 | 213 |