Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix codeql warnings #1345

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions avogadro/qtplugins/cp2kinput/cp2kinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#ifndef AVOGADRO_QTPLUGINS_QUANTUMINPUT_H
#define AVOGADRO_QTPLUGINS_QUANTUMINPUT_H
#ifndef AVOGADRO_QTPLUGINS_CP2KINPUT_H
#define AVOGADRO_QTPLUGINS_CP2KINPUT_H

#include <avogadro/qtgui/extensionplugin.h>

Expand Down Expand Up @@ -63,4 +63,4 @@ private slots:
} // namespace QtPlugins
} // namespace Avogadro

#endif // AVOGADRO_QTPLUGINS_QUANTUMINPUT_H
#endif // AVOGADRO_QTPLUGINS_CP2KINPUT_H
6 changes: 3 additions & 3 deletions avogadro/qtplugins/focus/focus.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#ifndef AVOGADRO_QTPLUGINS_RESETVIEW_H
#define AVOGADRO_QTPLUGINS_RESETVIEW_H
#ifndef AVOGADRO_QTPLUGINS_FOCUS_H
#define AVOGADRO_QTPLUGINS_FOCUS_H

#include <Eigen/Geometry>
#include <avogadro/qtgui/extensionplugin.h>
Expand All @@ -14,7 +14,7 @@ namespace Avogadro {
namespace QtPlugins {

/**
* @brief The ResetView class is an extension to center the camera in the best
* @brief The Focus class is an extension to center the camera in the best
* fit panel or the default camera position
*/
class Focus : public Avogadro::QtGui::ExtensionPlugin
Expand Down
6 changes: 3 additions & 3 deletions avogadro/qtplugins/force/force.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#ifndef AVOGADRO_QTPLUGINS_WIREFRAME_H
#define AVOGADRO_QTPLUGINS_WIREFRAME_H
#ifndef AVOGADRO_QTPLUGINS_FORCE_H
#define AVOGADRO_QTPLUGINS_FORCE_H

#include <avogadro/qtgui/sceneplugin.h>

Expand Down Expand Up @@ -45,4 +45,4 @@ class Force : public QtGui::ScenePlugin
} // end namespace QtPlugins
} // end namespace Avogadro

#endif // AVOGADRO_QTPLUGINS_WIREFRAME_H
#endif // AVOGADRO_QTPLUGINS_FORCE_H
6 changes: 3 additions & 3 deletions avogadro/qtplugins/gamessinput/gamessinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#ifndef AVOGADRO_QTPLUGINS_QUANTUMINPUT_H
#define AVOGADRO_QTPLUGINS_QUANTUMINPUT_H
#ifndef AVOGADRO_QTPLUGINS_GAMESSINPUT_H
#define AVOGADRO_QTPLUGINS_GAMESSINPUT_H

#include <avogadro/qtgui/extensionplugin.h>

Expand Down Expand Up @@ -65,4 +65,4 @@ private slots:
}
}

#endif // AVOGADRO_QTPLUGINS_QUANTUMINPUT_H
#endif // AVOGADRO_QTPLUGINS_GAMESSINPUT_H
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