Skip to content

Commit

Permalink
Fix some potential uninitialized variables
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Sep 14, 2023
1 parent 9066d37 commit 8f70bd3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions avogadro/core/coordinateblockgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ std::string CoordinateBlockGenerator::generateCoordinateBlock()
const Index numAtoms = m_molecule->atomCount();
Atom atom;
unsigned char atomicNumber;
const char* symbol;
const char* name;
const char* symbol = "\0";
const char* name = "\0";
Vector3 pos3d;
Vector3 fpos3d;
const UnitCell* cell =
Expand Down
2 changes: 1 addition & 1 deletion avogadro/core/dihedraliterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Dihedral DihedralIterator::begin()
Index c = bc.second;

// find an a
Index a;
Index a = 0;
for (const auto maybeA : graph.neighbors(b)) {
if (maybeA != c) {
a = maybeA;
Expand Down
2 changes: 1 addition & 1 deletion avogadro/core/elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ unsigned char Elements::guessAtomicNumber(const std::string& inputStr)
str[0] = static_cast<char>(toupper(static_cast<int>(str[0])));

int length = str.size();
unsigned char atomicNumber;
unsigned char atomicNumber = InvalidElement;
while (length > 0) {
if (length > 3)
atomicNumber = atomicNumberFromName(str.substr(0, length));
Expand Down
6 changes: 4 additions & 2 deletions avogadro/io/gromacsformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool GromacsFormat::read(std::istream& in, Molecule& molecule)
{
string buffer;
string value;
Residue* r;
Residue* r = nullptr;
size_t currentResidueId = 0;

// Title
Expand Down Expand Up @@ -138,7 +138,9 @@ bool GromacsFormat::read(std::istream& in, Molecule& molecule)
// Atom name:
value = trimmed(buffer.substr(10, 5));
Atom atom;
int atomicNum = r->getAtomicNumber(value);
int atomicNum = 0;
if (r != nullptr)
r->getAtomicNumber(value);
if (atomicNum) {
atom = molecule.addAtom(atomicNum);
} else {
Expand Down
1 change: 1 addition & 0 deletions avogadro/io/lammpsformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ bool LammpsDataFormat::write(std::ostream& outStream, const Core::Molecule& mol)

std::ostringstream massStream, atomStream, bondStream;
double xmin, xmax, ymin, ymax, zmin, zmax;
xmin = xmax = ymin = ymax = zmin = zmax = 0.0;

size_t numAtoms = mol2.atomCount();
outStream << to_string(numAtoms) << " atoms\n";
Expand Down
4 changes: 2 additions & 2 deletions avogadro/io/pdbformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol)
{
string buffer;
std::vector<int> terList;
Residue* r;
Residue* r = nullptr;
size_t currentResidueId = 0;
bool ok(false);
int coordSet = 0;
Expand Down Expand Up @@ -173,7 +173,7 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol)
} else if (coordSet == 0) {
Atom newAtom = mol.addAtom(atomicNum);
newAtom.setPosition3d(pos);
if (r) {
if (r != nullptr) {
r->addResidueAtom(atomName, newAtom);
}
rawToAtomId.push_back(mol.atomCount() - 1);
Expand Down
2 changes: 2 additions & 0 deletions avogadro/io/turbomoleformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ bool TurbomoleFormat::read(std::istream& inStream, Core::Molecule& mol)

// possible lattice constants
Real a, b, c, alpha, beta, gamma;
a = b = c = 100.0;
alpha = beta = gamma = 90.0;
// defaults if periodicity is not 3
Vector3 v1(100.0, 0.0, 0.0);
Vector3 v2(0.0, 100.0, 0.0);
Expand Down
2 changes: 1 addition & 1 deletion avogadro/qtplugins/templatetool/templatetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void TemplateTool::atomLeftClick(QMouseEvent*)
return;

// Find dummy atom in template and get all necessary info
size_t templateDummyIndex;
size_t templateDummyIndex = 0;
std::vector<size_t> templateLigandIndices;
std::vector<size_t> templateLigandUIDs;
for (size_t i = 0; i < templateMolecule.atomCount(); i++) {
Expand Down

0 comments on commit 8f70bd3

Please sign in to comment.