Project

General

Profile

Bug #872

Precedence error in gmx_mindist.c leads to omitted output in atm-pair (-o) file for g_mindist

Added by Matthew Zwier almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
analysis tools
Target version:
Affected version - extra info:
Affected version:
Difficulty:
uncategorized
Close

Description

Line 390 of gmx_mindist.c is responsible for only printing out atom pairs of minimum/maximum distance when a valid distance has been found:

    if ( bMin?min1:max1 != -1 )
      if (atm)
       fprintf(atm,"%12e  %12d  %12d\n",
               output_env_conv_time(oenv,t),1+(bMin ? min1 : max1),

but the "!=" operator binds more tightly than the ternary conditional "?:", so the resulting test evaluates as:
    if ( bMin?(min1):(max1 != -1) )

which fails whenever the atom from the first group of minimum/maximum distance to the second group is the first atom in the topology (with index 0). Explicit parentheses around the bMin conditional correct this problem:
    if ( (bMin?min1:max1) != -1 )

A (tested) patch against the latest gromacs-release-4.5-patches is attached.

gmx_mindist_ternary_prec.patch (482 Bytes) gmx_mindist_ternary_prec.patch patch fixing the problem Matthew Zwier, 01/30/2012 11:06 PM

Associated revisions

Revision dcb9b355 (diff)
Added by Mark Abraham almost 6 years ago

Corrected use of ?: in conditional

Patch contributed by Matthew Zwier to fix the incorrect use of
precedence of ?: and != operators.

Fixes #872

Change-Id: Ie4bbc3cbdaf33fc0386d12c2e142a9c076c2e946

History

#1 Updated by Mark Abraham almost 6 years ago

Thanks. Patch submitted to gerrit. https://gerrit.gromacs.org/#/c/448/

#2 Updated by Mark Abraham almost 6 years ago

  • Status changed from New to Closed
  • Assignee changed from David van der Spoel to Mark Abraham

Also available in: Atom PDF