diff --git a/src/stream_cdf_i.c b/src/stream_cdf_i.c
index f15c5b0144e2fa9e6898797f52b7625f9e9c6aa9..3a3945db4bd97ba31e8c0de8614bfd2746001735 100644
--- a/src/stream_cdf_i.c
+++ b/src/stream_cdf_i.c
@@ -3267,7 +3267,7 @@ void cdf_copy_attint(int fileID, int vlistID, nc_type xtype, size_t attlen, char
   int attint[8];
   int *pattint = (attlen > 8) ? (int*) malloc(attlen*sizeof(int)) : attint;
   cdfGetAttInt(fileID, NC_GLOBAL, attname, attlen, pattint);
-  int datatype = (xtype == NC_SHORT) ? CDI_DATATYPE_INT16 : CDI_DATATYPE_INT32;
+  const int datatype = (xtype == NC_SHORT) ? CDI_DATATYPE_INT16 : CDI_DATATYPE_INT32;
   cdiDefAttInt(vlistID, CDI_GLOBAL, attname, datatype, (int)attlen, pattint);
   if (attlen > 8) free(pattint);
 }
@@ -3276,9 +3276,9 @@ static
 void cdf_copy_attflt(int fileID, int vlistID, nc_type xtype, size_t attlen, char *attname)
 {
   double attflt[8];
-  double *pattflt = (attlen > 8) ? (double*) malloc(attlen*sizeof(int)) : attflt;
+  double *pattflt = (attlen > 8) ? (double*) malloc(attlen*sizeof(double)) : attflt;
   cdfGetAttDouble(fileID, NC_GLOBAL, attname, attlen, pattflt);
-  int datatype = (xtype == NC_FLOAT) ? CDI_DATATYPE_FLT32 : CDI_DATATYPE_FLT64;
+  const int datatype = (xtype == NC_FLOAT) ? CDI_DATATYPE_FLT32 : CDI_DATATYPE_FLT64;
   cdiDefAttFlt(vlistID, CDI_GLOBAL, attname, datatype, (int)attlen, pattflt);
   if (attlen > 8) free(pattflt);
 }