Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

use of assert() macro to check file problems

Hello,

There are several places in the netCDF library where the assert()
macro is the only check on file problems.  For example, in 
v1h_get_nc_type(), assert checks for a valid netCDF var type.  The
problem is, if an nc file gets corrupted (for example, truncated during
a copy etc.) this is the only way to catch the error.  If assert() 
catches the error, the program aborts.  

I have a distributed server application that allows remote access to netCDF
files through a CORBA interface.  If the server is linked with a version 
of the netCDF lib that includes assert(), then the server will crash 
(abort) as soon as a corrupted file is opened.  This, of course, is 
unacceptable for a server process.  On the other hand, if I link with a
NDEBUG version of the lib, the file errors are ignored and garbage is 
returned.  It would be much better if these assert()'s were replaced with
code to return an error value.  My understanding is that assert() should
only be used to catch programmer errors, not as an error handling for
external input (netCDF flies).

Thanks,

Mike McCarrick
--

Dr. Michael McCarrick                           (202) 223-8808 voice
Advanced Power Technologies, Inc., Wash DC      (202) 223-1377 fax


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690