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

Dev/pvs studio cleanups2 #2877

Merged
merged 9 commits into from
Jan 22, 2020

Conversation

greglandrum
Copy link
Member

This is like #2531: a series of fixes suggested by PVS/Studio.

Again, it's mostly warnings, but there are a couple of real bug fixes in there.

Note that one of the fixes here is redundant with #2875 (I applied a cherry pick of the relevant commit to do that PR so that we can be sure it's in the release notes).

@greglandrum greglandrum added bug Cleanup Code cleanup and refactoring labels Jan 14, 2020
@greglandrum greglandrum added this to the 2020_03_1 milestone Jan 14, 2020
@@ -1221,8 +1220,8 @@ O3A::O3A(int (*costFunc)(const unsigned int, const unsigned int, double,
double (*weightFunc)(const unsigned int, const unsigned int, void *),
double (*scoringFunc)(const unsigned int, const unsigned int, void *),
void *data, ROMol &prbMol, const ROMol &refMol, const int prbCid,
const int refCid, boost::dynamic_bitset<> *prbHvyAtoms,
boost::dynamic_bitset<> *refHvyAtoms, const bool reflect,
const int refCid, const boost::dynamic_bitset<> &prbHvyAtoms,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching these two dynamic_bitset arguments to references ends up clearing up a bug (likely never observed in real code) when prbHvyAtoms was null.

@@ -689,8 +690,7 @@ void addRecursiveQueries(
RWMol *m = 0;
try {
m = SmartsToMol(maybeSmarts);
if (!m)
throw KeyErrorException(pval);
if (!m) throw KeyErrorException(pval);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy has an option to automatically add brackets to single-line blocks. I find that I prefer the explicit brackets, not sure how others feel.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If's feel naked without braces.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed that they are desirable. I will look at adding that option and doing a pass to reformat everything after we get this one merged

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that was really an aside, sorry.

@@ -176,14 +176,14 @@ def test3MultiConf(self):
cids = rdDistGeom.EmbedMultipleConfs(mol, 10, maxAttempts=30, randomSeed=100,
useExpTorsionAnglePrefs=False,
useBasicKnowledge=False)
energies = [115.460, 105.891, 109.868, 104.415,
92.944, 140.917, 139.468, 95.081, 123.528, 107.885]
energies = [116.330, 106.246, 109.816, 104.890,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense that these values changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was part of the fix that's in #2875

@@ -146,6 +145,7 @@ Conformer *ParseConfData(std::istream *inStream, unsigned int &line, RWMol *mol,
boost::split(splitLine, tempStr, boost::is_any_of(" \t"),
boost::token_compress_on);
if (splitLine.size() < 3) {
delete conf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@greglandrum
Copy link
Member Author

@d-b-w, @bp-kelley : you guys commented, but didn't indicate whether or not you approve.
Ok to merge?

Copy link
Contributor

@bp-kelley bp-kelley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are a ton of formatting changes, this is slow going for me.

return true;
}

const RGROUPS &EvenSamplePairsStrategy::next() {
nslack = 0;
while (m_numPermutationsProcessed < rdcast<boost::uint64_t>(m_numPermutations)) {
bool added = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was added dropped?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, the return is the control flow here.

@@ -1600,9 +1600,6 @@ ROMol *reduceProductToSideChains(const ROMOL_SPTR &product,

if (atommapno) {
Atom *at = mol->getAtomWithIdx(idx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't at be null? What is the guarantee here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atom::getAtomWtihIdx() does not return nullptr. It has a POSTCONDITION on its result.

std::vector<MatchVectType> fgpMatches;
std::vector<MatchVectType>::const_iterator mati;
VECT_INT_VECT matches; // all matches on the molecule - list of list of atom ids
VECT_INT_VECT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is odd formatting

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. Hopefully it will get fixed when I do the full clang-tidy run

@@ -656,8 +657,8 @@ std::pair<std::string, RWMol*> MaximumCommonSubgraph::generateResultSMARTSAndQue
// Generate result's SMARTS

// create molecule from MCS for MolToSmarts()
RWMol *mol = new RWMol();
const RingInfo *ri = QueryMolecule->getRingInfo();
RWMol* mol = new RWMol();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to say, I'm not a fan of this formatting.

RWMol* m, mol;

Doesn't do what you might expect. The *,& qualifier is a qualifier for the variable not the type unless you use a typedef.

Copy link
Contributor

@d-b-w d-b-w Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just double checked, and clang-format formats these lines differently:

RWMol* mol = new RWMol();

and:

RWMol *m, mol;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd, I'm only getting that style when I use --style=Mozilla

clang-format foo.cpp --style=Mozilla

void
f()
{
  RWMol* m = new RWMol(m);
  RWMol *m, mol;
}

clang-format foo.cpp --style=file (.clang-format from rdkit)

void f() {
  RWMol *m = new RWMol(m);
  RWMol *m, mol;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something is probably messed up with my vs-code config. I will take a look.
But, again, this will hopefully be dealt with when I re-run clang-tidy after this PR is merged

@@ -2321,6 +2321,39 @@ void testMACCS() {
delete m1;
delete fp1;
}
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test new?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, PVS/Studio gave some spurious warnings/errors about parts of the MACCS generation code and I wanted to add a test to make sure that they actually were incorrect

@@ -329,6 +330,9 @@ struct LeaderPickerState {
v.resize(count);
for (unsigned int i = 0; i < count; i++) v[i] = i;
left = count;
threshold = 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but these would be better in the initializer list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@@ -372,7 +372,7 @@ MolOps::SanitizeFlags sanitizeMol(ROMol &mol, boost::uint64_t sanitizeOps,
}

RWMol *getEditable(const ROMol &mol) {
RWMol *res = static_cast<RWMol *>(new ROMol(mol, false));
RWMol *res = new RWMol(mol, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the formatting isn't consistent here for RWMol* res versus RWMol *res.

PRECONDITION(rootedAtAtom < 0 || static_cast<unsigned int>(
rootedAtAtom) < mol.getNumAtoms(),
"rootedAtomAtom must be less than the number of atoms");
PRECONDITION(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fairly sure this precondition is always true due to the mod (%)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@@ -137,6 +144,8 @@ static unsigned int NMDetermineComponents(RWMol *mol, unsigned int *parts,

static std::string NMMolecularFormula(RWMol *mol, const unsigned int *parts,
unsigned int part) {
PRECONDITION(mol, "bad molecule");
PRECONDITION((!part || parts), "bad parts pointer");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear there is no parts[part==0] and part is 1 indexed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's correct

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I will add a test to make sure the molformula hash works when the molecule has multiple fragments

@greglandrum
Copy link
Member Author

@bp-kelley, @d-b-w : ok to merge this with the changes I made?

@greglandrum greglandrum merged commit ec366c1 into rdkit:master Jan 22, 2020
@greglandrum greglandrum deleted the dev/pvs_studio_cleanups2 branch January 22, 2020 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Cleanup Code cleanup and refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants