[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #LUG-158105]: nc_get_att_string behaviour



Hi Thomas,

> I have a question about the correct use of nc_get_att_string.
> 
> int nc_get_att_string (int ncid, int varid, const char *name, char **ip);
> 
> I understand the function should be used as follows:
> 
> 1) user determines the number of strings in the attribute (for
> example using nc_inq_att_len).
> 
> 2) user creates a buffer ip, holding a number of char*'s, long enough
> to store the required number of attributes.  The char*'s in the
> buffer need not be initialized/allocated.
> 
> 3) when calling nc_get_att_string, the netCDF library will allocate
> character buffers to hold the string attributes, and store their
> addresses in the char** ip.
> 
> 4) the user should free the char*'s ip[0],ip[1,],... when he/she is
> done using the strings.
> 
> Can you confirm this is the correct way to use the function?  I
> believe the behaviour of the function w.r.t. malloc/free (who
> allocates, and who calls free() ) is not explicitly documented.

You're right, I think the documentation for that function is currently 
inadequate. There's a test program in the distribution that demonstrates
the intended usage, starting at line 133:

  https://github.com/Unidata/netcdf-c/blob/master/nc_test4/tst_strings.c

It shows use of the nc_free_string() function to free string data, which is
malloced by the library.

Thanks for pointing out the missing documentation problem.

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: LUG-158105
Department: Support netCDF
Priority: Normal
Status: Closed