move ncid check to the first and add varid check before name check

This commit is contained in:
Wei-keng Liao 2016-10-13 02:12:26 -05:00
parent df91c19f3c
commit fbbed1f9ff
3 changed files with 9 additions and 3 deletions

View File

@ -441,6 +441,7 @@ NCP_get_att(
if(status != NC_NOERR) return status;
status = NCP_inq_att(ncid,varid,name,&xtype,NULL);
if(status != NC_NOERR) return status;
if(memtype == NC_NAT) memtype = xtype;
@ -487,6 +488,14 @@ NCP_put_att(
int status;
MPI_Offset mpilen;
/* check if ncid is valid */
status = NC_check_id(ncid, &nc);
if(status != NC_NOERR) return status;
/* check if varid is valid */
status = ncmpi_inq_varnatts(nc->int_ncid, varid, NULL);
if (status != NC_NOERR) return status;
if (!name || (strlen(name) > NC_MAX_NAME))
return NC_EBADNAME;
@ -495,9 +504,6 @@ NCP_put_att(
if(((unsigned long) len) > X_INT_MAX)
return NC_EINVAL;
status = NC_check_id(ncid, &nc);
if(status != NC_NOERR) return status;
mpilen = len;
switch (memtype) {