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

オープン 初心者向け
#1,333 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, cpp
領域
cli

調査の方向性

src/tdat/chemistry/Fragment.C の 3897 行目付近から始めてください。ここで Fragment::covalentRadii() は iter を進めないため、result[0] にしか書き込まれません。数行下にある Fragment::atomicNumbers() は (*iter++) を使っているので、これと比較してください。covalentRadii を呼び出している箇所がないことを確認してください(1810~1929 行目のローカル変数は無関係です)。メソッドを削除するか修正して、返している van der Waals 半径に合う名前に変更し、include/tdat/Fragment.H:239 の宣言も合わせて更新できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C
スター
10
フォーク
8
平均マージ
6時間 32分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

FriendsofECCE/ECCE のほかの issue

FriendsofECCE/ECCE の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。