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

[netCDF #PHC-148715]: Suggested change to netcdf-cxx-4.2 code


Thank you for the patch.  The C++ 4.2 libraries are deprecated (as you note), 
but I will take a look to see if the same issue occurs in the latest C++ 
libraries and, if so, will apply your patch to address the issue.  

Thanks again, have a great day,


> Hi
> In debugging netcdf apps using valgrind, I get warnings related to the
> use of uninitialized variables.
> In the older C++ lib, I suggest that you change the NcVar constructor to
> be as follows:
> NcVar::NcVar(NcFile* nc, int id)
> : NcTypedComponent(nc), the_id(id)
> {
> char nam[NC_MAX_NAME];
> memset(nam, 0, NC_MAX_NAME);   <<<===== add this line
> if (the_file
> && NcError::set_err(
> nc_inq_varname(the_file->id(), the_id, nam)
> ) == NC_NOERR) {
> the_name = new char[1 + strlen(nam)];
> strcpy(the_name, nam);
> } else {
> the_name = 0;
> }
> init_cur();
> }
> i.e. add the memset call to clear the nam variable before it is used.
> I did this in a valgrind test environment and it cleared up a lot of
> warnings.
> Thanks
> Mike Dixon

Ticket Details
Ticket ID: PHC-148715
Department: Support netCDF
Priority: Normal
Status: Closed

NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.