Commit 123d4138 authored by Fabian Wachsmann's avatar Fabian Wachsmann
Browse files

Replaced strcpy by memcpy and added Free for char arrays

parent b7dea9bc
......@@ -2881,8 +2881,8 @@ int cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
if ( ncvars[zvarid].ndims == 2 )
{
zprec = CDI_DATATYPE_UINT8;
zclength = ncdims[ncvars[zvarid].dimids[1]].len;
cdf_load_cvals(zsize*zclength, zvarid, ncvar, &zcvals, zsize);
zclength = (size_t)ncdims[ncvars[zvarid].dimids[1]].len;
cdf_load_cvals(zsize*zclength, zvarid, ncvar, &zcvals, (size_t)zsize);
}
}
......@@ -2980,6 +2980,12 @@ int cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
cdiZaxisDefKeyStr(zaxisID, CDI_KEY_VDIMNAME, strlen(ncdims[vdimid].name)+1, ncdims[vdimid].name);
*/
if ( zvar ) Free(zvar);
if ( zcvals )
{
for ( size_t i = 0; i < zsize; i++ )
Free(zcvals[i]);
Free(zcvals);
}
if ( lbounds ) Free(lbounds);
if ( zvarid != CDI_UNDEFID )
......
......@@ -274,7 +274,12 @@ void zaxisDestroyKernel( zaxis_t * zaxisptr )
int id = zaxisptr->self;
if ( zaxisptr->vals ) Free( zaxisptr->vals );
if ( zaxisptr->cvals ) Free( zaxisptr->cvals );
if ( zaxisptr->cvals )
{
for ( int i=0; i<zaxisptr->size; i++)
Free(zaxisptr->cvals[i]);
Free( zaxisptr->cvals );
}
if ( zaxisptr->lbounds ) Free( zaxisptr->lbounds );
if ( zaxisptr->ubounds ) Free( zaxisptr->ubounds );
if ( zaxisptr->weights ) Free( zaxisptr->weights );
......@@ -793,7 +798,7 @@ void zaxisDefCvals(int zaxisID, const char **cvals, size_t clen)
for ( size_t ilev = 0; ilev < size; ++ilev )
{
zaxisptr->cvals[ilev] = Malloc((clen+1)*sizeof(char));
strcpy(zaxisptr->cvals[ilev],cvals[ilev]);
memcpy(zaxisptr->cvals[ilev],cvals[ilev], clen);
zaxisptr->cvals[ilev][clen] = '\0';
}
reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
......@@ -1061,8 +1066,9 @@ int zaxisInqCLevels(int zaxisID, char ***clevels)
(*clevels) = Malloc(size*sizeof(char*));
for ( int i = 0; i < size; i++ )
{
(*clevels)[i] = Malloc(clen*sizeof(char));
strcpy((*clevels)[i],zaxisptr->cvals[i]);
(*clevels)[i] = Malloc((clen+1)*sizeof(char));
memcpy((*clevels)[i], zaxisptr->cvals[i], clen);
(*clevels)[i][clen] = '\0';
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment