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.
>Keywords: 199412191029.AA22866 Hi Bernward, > In netcdf2.3.2pl2 I found the following bug: > > If you have a variable with attributes and you do the following: > > 1) Delete all attributes from the variable. > 2) Close the file without adding new attributes to this variable. > 3) Open the file again and put it into define mode. > 4) Add an attribute to the variable. > > the program now stops with "ncattput: extend_array: Invalid argument". > > I could fix this by changing NC_incr_array in array.c: > > Replace > > array->values = (Void*)realloc(array->values, > (array->count +1) * array->szof) ; > > by > > if (array->values == NULL) > { > array->values = > (Void*)malloc((array->count +1) * array->szof) ; > } else { > array->values = (Void*)realloc(array->values, > (array->count +1) * array->szof) ; > } > > But I don't know if this is save. > > The following program can be used to trigger the bug: > > #include <netcdf.h> > #include <stdio.h> > main() > { > int ncid; > int varid; > int dimid; > ncopts = NC_VERBOSE + NC_FATAL; > > ncid = nccreate("tst.nc",NC_CLOBBER); > > dimid = ncdimdef(ncid,"time",10); > > > varid = ncvardef (ncid, "V",NC_FLOAT,1,&dimid); > > ncattput(ncid, varid, "units",NC_CHAR, strlen("m/s")+1,"m/s"); > > ncattdel(ncid, varid, "units"); > > ncclose (ncid); > > ncid = ncopen("tst.nc",NC_WRITE); > > ncredef(ncid); > > varid = ncvarid(ncid,"V"); > > ncattput(ncid, varid, "units",NC_CHAR, strlen("cm/s")+1,"cm/s"); > > ncclose(ncid); > } Thanks for reporting this. Your fix looks OK to me. We will incorporate this or a similar fix into the next release. -- Russ Rew UCAR Unidata Program address@hidden P.O. Box 3000 http://www.unidata.ucar.edu/ Boulder, CO 80307-3000