Fragment::covalentRadii() writes every value to result[0] and returns van der Waals radii

Ouverte Adaptée aux débutants
#1,333 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
62/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
c, cpp
Domaine
cli

Piste de recherche

Commence à src/tdat/chemistry/Fragment.C vers la ligne 3897, où Fragment::covalentRadii() n'avance jamais iter, de sorte que seul result[0] est écrit. Compare avec Fragment::atomicNumbers() quelques lignes plus bas, qui utilise (*iter++). Vérifie que rien n'appelle covalentRadii (la variable locale des lignes 1810-1929 n'a aucun rapport). C'est terminé lorsque la méthode est supprimée ou corrigée, puis renommée pour correspondre aux rayons de van der Waals qu'elle renvoie, et que la déclaration dans include/tdat/Fragment.H:239 est mise à jour en conséquence.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

src/tdat/chemistry/Fragment.C:3897, in full:

///////////////////////////////////////////////////////////////////////////////
//
//  Description
//    Return a Dynamically Allocated, c-style, Ordered Array of crs.
//    The Caller must Deallocate the Array Memory.
//
///////////////////////////////////////////////////////////////////////////////
double* Fragment::covalentRadii(void) const
{
  TPerTab tpt;
  double* result = new double[numAtoms()];
  double* iter = result;

  int cnt = p_atoms.size();
  for (int idx=0; idx<cnt; idx++) {
    (*iter) = tpt.vwr(tpt.atomicNumber(p_atoms[idx]->atomicSymbol()));
  }
  return result;
}

Two defects.

1. The output pointer never advances. iter is assigned but never
incremented, so every atom's value is written to result[0] and
result[1..numAtoms()-1] is returned uninitialised. The caller, which the
comment tells to delete[] the array, would read heap garbage for every atom
after the first.

The sibling function immediately below it, Fragment::atomicNumbers()
(Fragment.C:3917), is the same loop written correctly, with (*iter++).

2. It is misnamed. The function is covalentRadii, but it calls
TPerTab::vwr — it returns van der Waals radii. TPerTab has a separate
covalentRadius(int) (include/tdat/TPerTab.H:81), which this does not call.
The doc comment ("an Ordered Array of crs") says covalent radii too.

Callers

None. Searching the whole tree for covalentRadii:

  • include/tdat/Fragment.H:239 — the declaration,
    virtual double* covalentRadii(void) const;
  • src/tdat/chemistry/Fragment.C:3897 — this definition.
  • src/tdat/chemistry/Fragment.C:1810-1929 — an unrelated local variable
    of the same name in the bond-generation code. It is a plain
    double* covalentRadii = new double[nAtoms], filled from
    tpt.covalentRadius(num) * tpt.covalentRadiusTolerance(num) and delete[]d
    at line 1929. That code is correct and does use covalent radii; it does not
    call the method.
  • include/tdat/TPerTab.H:87-88 and src/tdat/chemistry/TPerTab.C:205-229 —
    parameter names of TPerTab::writeRadiiOverrides(double*, double*, double*). Unrelated.

So the method is declared once, defined once, and called from nowhere.

Severity

A latent defect in dead code, not a live bug: nothing currently calls it, so
nothing currently reads the uninitialised tail. But it is public and
virtual, so a subclass can override it and any future caller can reach it,
and the misnaming means a caller would get the wrong quantity even after the
loop bug is fixed. It allocates with new[] and its comment makes the caller
responsible for freeing — an interface that is easy to use wrongly even when
it works.

Recommendation

Delete it, or fix and rename it (vanderWaalsRadii(), returning a
std::vector<double> rather than a raw new[] array) — but it should not be
left as it is.

This matters now because of #1332: surface-area work is exactly the kind of
code that reaches for a Fragment method named covalentRadii() or sitting
next to one, and #1332 turns on which radius set is used. A function that is
named for one radius set and silently returns another, with only its first
element valid, is the worst possible thing for that code to find.

Langage dominant
C
Étoiles
10
Forks
8
Merge moyen
6 h 32 min
PR mergées (30 j)
1

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de FriendsofECCE/ECCE

Toutes les issues de FriendsofECCE/ECCE

Issues similaires

Plus d'issues C

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.