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

ncplot crashes with "Floating point exception" when TimeInterval global attribute not present #1

Closed
nsdecicco opened this issue Jun 6, 2016 · 1 comment

Comments

@nsdecicco
Copy link

Issue

If a NetCDF file is opened in ncplot that is missing a (properly defined) TimeInterval global attribute, ncplot will crash with this message

Floating point exception

the moment the user attempts to view a variable by selecting it from the list of all variables in the file.

Steps to reproduce

  1. Download the test file contained in test.zip.

  2. Invoke ncplot with

    ncplot test.nc
    
  3. Observe that, for this file, which contains the TimeInterval global attribute, ncplot does not crash when attempting to view a variable.

  4. Remove the TimeInterval global attribute using ncatted (from the NetCDF Operators package):

    ncatted -a TimeInterval,global,d,, test.nc noti.nc
    
  5. Run

    ncplot noti.nc
    

    and observe that ncplot will crash the moment the user attempts to view a variable.

Cause

The GetTimeInterval function in in dataIO.c on lines 854-882 reads and parses the TimeInterval NetCDF global attribute to obtain the start and end time. From here, FileStartTime and FileEndTime members of the curFile struct are set. These values are later used to populate the UserStartTime and UserEndTime variables in dataIO.c:

  if (timeSeg)  /* From command line only   */
    {
    // ... snip ...
    }
  else
    {
    memcpy((char *)UserStartTime, (char *)curFile->FileStartTime,4*sizeof(int));
    memcpy((char *)UserEndTime, (char *)curFile->FileEndTime,4*sizeof(int));
    }

which are then used, in turn, to compute a value NumberSeconds,

NumberSeconds = UserEndTime[3] - UserStartTime[3];

which ultimately causes the crash (due to a division by zero error) on line 490 in X.c:

halfSecond = plot->x.HD / NumberSeconds / 2;

Mitigation strategies

This would be avoidable if the start and end times were not read from the NetCDF file as an attribute, but computed from the Time field itself.

Desired behavior

Ideally, ncplot would at least warn the user that the TimeInterval global attribute must be present; i.e., ncplot should throw an error if the TimeInterval global attribute is not present.

@topher800
Copy link
Member

Warning has been added, and functions where divide by NumberSeconds return if NumberSeconds equals zero.

Agreed Start/End time should be computed from Time variable. TimeInterval predates the Time variable, so this is a legacy issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants