diff --git a/src/create_bonds.cpp b/src/create_bonds.cpp index c6d3f1838e..5355ce2b7c 100644 --- a/src/create_bonds.cpp +++ b/src/create_bonds.cpp @@ -319,8 +319,6 @@ void CreateBonds::many() void CreateBonds::single_bond() { - int m; - // check that 2 atoms exist const int nlocal = atom->nlocal; @@ -341,7 +339,8 @@ void CreateBonds::single_bond() int **bond_type = atom->bond_type; tagint **bond_atom = atom->bond_atom; - if ((m = idx1) >= 0) { + int m = idx1; + if ((m >= 0) && (m < nlocal)) { if (num_bond[m] == atom->bond_per_atom) error->one(FLERR, "New bond exceeded bonds per atom in create_bonds"); bond_type[m][num_bond[m]] = btype; @@ -352,7 +351,8 @@ void CreateBonds::single_bond() if (force->newton_bond) return; - if ((m = idx2) >= 0) { + m = idx2; + if ((m >= 0) && (m < nlocal)) { if (num_bond[m] == atom->bond_per_atom) error->one(FLERR, "New bond exceeded bonds per atom in create_bonds"); bond_type[m][num_bond[m]] = btype; @@ -365,8 +365,6 @@ void CreateBonds::single_bond() void CreateBonds::single_angle() { - int m; - // check that 3 atoms exist const int nlocal = atom->nlocal; @@ -391,7 +389,8 @@ void CreateBonds::single_angle() tagint **angle_atom2 = atom->angle_atom2; tagint **angle_atom3 = atom->angle_atom3; - if ((m = idx2) >= 0) { + int m = idx2; + if ((m >= 0) && (m < nlocal)) { if (num_angle[m] == atom->angle_per_atom) error->one(FLERR, "New angle exceeded angles per atom in create_bonds"); angle_type[m][num_angle[m]] = atype; @@ -404,7 +403,8 @@ void CreateBonds::single_angle() if (force->newton_bond) return; - if ((m = idx1) >= 0) { + m = idx1; + if ((m >= 0) && (m < nlocal)) { if (num_angle[m] == atom->angle_per_atom) error->one(FLERR, "New angle exceeded angles per atom in create_bonds"); angle_type[m][num_angle[m]] = atype; @@ -414,7 +414,8 @@ void CreateBonds::single_angle() num_angle[m]++; } - if ((m = idx3) >= 0) { + m = idx3; + if ((m >= 0) && (m < nlocal)) { if (num_angle[m] == atom->angle_per_atom) error->one(FLERR, "New angle exceeded angles per atom in create_bonds"); angle_type[m][num_angle[m]] = atype; @@ -429,8 +430,6 @@ void CreateBonds::single_angle() void CreateBonds::single_dihedral() { - int m; - // check that 4 atoms exist const int nlocal = atom->nlocal; @@ -458,7 +457,8 @@ void CreateBonds::single_dihedral() tagint **dihedral_atom3 = atom->dihedral_atom3; tagint **dihedral_atom4 = atom->dihedral_atom4; - if ((m = idx2) >= 0) { + int m = idx2; + if ((m >= 0) && (m < nlocal)) { if (num_dihedral[m] == atom->dihedral_per_atom) error->one(FLERR, "New dihedral exceeded dihedrals per atom in create_bonds"); dihedral_type[m][num_dihedral[m]] = dtype; @@ -472,7 +472,8 @@ void CreateBonds::single_dihedral() if (force->newton_bond) return; - if ((m = idx1) >= 0) { + m = idx1; + if ((m >= 0) && (m < nlocal)) { if (num_dihedral[m] == atom->dihedral_per_atom) error->one(FLERR, "New dihedral exceeded dihedrals per atom in create_bonds"); dihedral_type[m][num_dihedral[m]] = dtype; @@ -483,7 +484,8 @@ void CreateBonds::single_dihedral() num_dihedral[m]++; } - if ((m = idx3) >= 0) { + m = idx3; + if ((m >= 0) && (m < nlocal)) { if (num_dihedral[m] == atom->dihedral_per_atom) error->one(FLERR, "New dihedral exceeded dihedrals per atom in create_bonds"); dihedral_type[m][num_dihedral[m]] = dtype; @@ -494,7 +496,8 @@ void CreateBonds::single_dihedral() num_dihedral[m]++; } - if ((m = idx4) >= 0) { + m = idx4; + if ((m >= 0) && (m < nlocal)) { if (num_dihedral[m] == atom->dihedral_per_atom) error->one(FLERR, "New dihedral exceeded dihedrals per atom in create_bonds"); dihedral_type[m][num_dihedral[m]] = dtype; @@ -510,8 +513,6 @@ void CreateBonds::single_dihedral() void CreateBonds::single_improper() { - int m; - // check that 4 atoms exist const int nlocal = atom->nlocal; @@ -539,7 +540,8 @@ void CreateBonds::single_improper() tagint **improper_atom3 = atom->improper_atom3; tagint **improper_atom4 = atom->improper_atom4; - if ((m = idx2) >= 0) { + int m = idx2; + if ((m >= 0) && (m < nlocal)) { if (num_improper[m] == atom->improper_per_atom) error->one(FLERR, "New improper exceeded impropers per atom in create_bonds"); improper_type[m][num_improper[m]] = dtype; @@ -553,7 +555,8 @@ void CreateBonds::single_improper() if (force->newton_bond) return; - if ((m = idx1) >= 0) { + m = idx1; + if ((m >= 0) && (m < nlocal)) { if (num_improper[m] == atom->improper_per_atom) error->one(FLERR, "New improper exceeded impropers per atom in create_bonds"); improper_type[m][num_improper[m]] = dtype; @@ -564,7 +567,8 @@ void CreateBonds::single_improper() num_improper[m]++; } - if ((m = idx3) >= 0) { + m = idx3; + if ((m >= 0) && (m < nlocal)) { if (num_improper[m] == atom->improper_per_atom) error->one(FLERR, "New improper exceeded impropers per atom in create_bonds"); improper_type[m][num_improper[m]] = dtype; @@ -575,7 +579,8 @@ void CreateBonds::single_improper() num_improper[m]++; } - if ((m = idx4) >= 0) { + m = idx4; + if ((m >= 0) && (m < nlocal)) { if (num_improper[m] == atom->improper_per_atom) error->one(FLERR, "New improper exceeded impropers per atom in create_bonds"); improper_type[m][num_improper[m]] = dtype;