• R/O
  • HTTP
  • SSH
  • HTTPS

Molby: コミット

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

変更サマリ

差分

--- a/MolLib/MolAction.c
+++ b/MolLib/MolAction.c
@@ -559,7 +559,7 @@ sMolActionUpdateSelectionAndParameterNumbering(Molecule *mol, const IntGroup *ig
559559 if (!is_insert)
560560 ig3 = IntGroupNew();
561561 for (j = 0; (up = ParameterGetUnionParFromTypeAndIndex(mol->par, i, j)) != NULL; j++) {
562- usave = *up;
562+ ParameterCopyOneWithType(&usave, up, i); /* Don't say usave = *up */
563563 if (ParameterRenumberAtoms(i, up, old_natoms, ip) && !is_insert) {
564564 IntGroupAdd(ig3, j, 1); /* This parameter is to be restored on undo */
565565 AssignArray(&upary, &count_upary, sizeof(UnionPar), count_upary, &usave);
@@ -780,7 +780,7 @@ MolActionPerform(Molecule *mol, MolAction *action)
780780 ip = (Int *)malloc(sizeof(Int) * 2 * result);
781781 if (ip == NULL)
782782 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);
784784 act2 = MolActionNew(gMolActionDeleteBonds, result * 2, ip);
785785 free(ip);
786786 needsRebuildMDArena = 1;
--- a/MolLib/Parameter.c
+++ b/MolLib/Parameter.c
@@ -283,6 +283,13 @@ ParameterGetSizeForType(int type)
283283 }
284284 }
285285
286+void
287+ParameterCopyOneWithType(UnionPar *dst, const UnionPar *src, int type)
288+{
289+ int size = ParameterGetSizeForType(type);
290+ memmove(dst, src, size);
291+}
292+
286293 UnionPar *
287294 ParameterRefGetPar(ParameterRef *pref)
288295 {
--- a/MolLib/Parameter.h
+++ b/MolLib/Parameter.h
@@ -202,6 +202,12 @@ int ParameterInsert(Parameter *par, Int type, const UnionPar *up, struct IntGrou
202202 int ParameterDelete(Parameter *par, Int type, UnionPar *up, struct IntGroup *where);
203203 int ParameterCopy(Parameter *par, Int type, UnionPar *up, struct IntGroup *where);
204204
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+
205211 int ParameterRenumberAtoms(Int type, UnionPar *up, Int oldnatoms, const Int *old2new);
206212 int ParameterDoesContainAtom(Int type, UnionPar *up, UInt atom_type, Int options);
207213
旧リポジトリブラウザで表示