This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>To: address@hidden >From: Harry Edmon <address@hidden> >Subject: NETCDF bug (fwd) - still there >Organization: Dept of Atmospheric Sciences, University of Washington >Keywords: 199611132130.AA29004 Hi Harry, > This bug still exists in the current version of netcdf (2.4.3) running > under Digital Unix 4.0A. The problem is that the file has a global > attribute with zero length. This causes malloc of zero bytes in ncdump > which returns nil, which is interpretted by ncdump as out of memory. > > Forwarded message: > > From harry Wed Feb 14 14:11:22 1996 > > Subject: NETCDF bug Actually, the message you forwarded from Feb 14 demonstrated a bug with zero-length *variable* attributes. This was fixed in netCDF 2.4, but not for zero-length *global* attributes. Sorry about that, these should have been handled by common code, and will be in netCDF-3. I've appended a patch for netCDF 2.4.3. --Russ *** /home/russ/upc/netcdf/netcdf-2.4.3/src/ncdump/ncdump.c Fri Jun 7 08:42:07 1996 --- ncdump.c Thu Nov 14 09:16:33 1996 *************** *** 1,7 **** /********************************************************************* * Copyright 1993, University Corporation for Atmospheric Research * See netcdf/README file for copying and redistribution conditions. ! * $Header: /upc/share/CVS/netcdf/ncdump/ncdump.c,v 1.50 1996/05/14 16:45:14 russ Exp $ *********************************************************************/ #include <stdio.h> --- 1,7 ---- /********************************************************************* * Copyright 1993, University Corporation for Atmospheric Research * See netcdf/README file for copying and redistribution conditions. ! * $Header: /upc/share/CVS/netcdf/ncdump/ncdump.c,v 1.51 1996/11/14 16:16:33 russ Exp $ *********************************************************************/ #include <stdio.h> *************** *** 372,387 **** Printf ("\t\t:%s = ", att.name); (void) ncattinq(ncid, NC_GLOBAL, att.name, &att.type, &att.len); ! att.val = (void *) malloc((unsigned) (att.len*nctypelen(att.type))); ! if (!att.val) { ! error("Out of memory!"); ! (void) ncclose(ncid); ! if (vlist) ! free(vlist); ! return; } - (void) ncattget(ncid, NC_GLOBAL, att.name, att.val); - pr_att_vals(att.type, att.len, att.val); Printf (" ;\n"); free ((char *) att.val); --- 372,393 ---- Printf ("\t\t:%s = ", att.name); (void) ncattinq(ncid, NC_GLOBAL, att.name, &att.type, &att.len); ! if (att.len == 0) { /* show 0-length attributes as empty strings */ ! att.type = NC_CHAR; ! att.val = (char *) malloc(1); ! att.len = 1; ! *(char *)att.val = '\0'; ! } else { ! att.val = (void *) malloc((unsigned) (att.len*nctypelen(att.type))); ! if (!att.val) { ! error("Out of memory!"); ! (void) ncclose(ncid); ! if (vlist) ! free(vlist); ! return; ! } ! (void) ncattget(ncid, NC_GLOBAL, att.name, att.val); } pr_att_vals(att.type, att.len, att.val); Printf (" ;\n"); free ((char *) att.val);