From 9d8ac7312072fbffb5940546ed8b109b3cb1f177 Mon Sep 17 00:00:00 2001 From: Jarle Ladstein Date: Thu, 12 Dec 2013 16:27:49 +0100 Subject: [PATCH] Removed several vector out of bounds debug assertion failures in ncGroup.cpp --- cxx4/ncGroup.cpp | 105 +++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/cxx4/ncGroup.cpp b/cxx4/ncGroup.cpp index 523b9b9..fcd9469 100644 --- a/cxx4/ncGroup.cpp +++ b/cxx4/ncGroup.cpp @@ -194,15 +194,15 @@ multimap NcGroup::getGroups(NcGroup::GroupLocation location // get the number of groups int groupCount = getGroupCount(); if (groupCount){ - vector ncids(groupCount); - int* numgrps=NULL; - // now get the id of each NcGroup and populate the ncGroups container. - ncCheck(nc_inq_grps(myId, numgrps,&ncids[0]),__FILE__,__LINE__); - for(int i=0; i(tmpGroup.getName(),tmpGroup)); - } - } + vector ncids(groupCount); + int* numgrps=NULL; + // now get the id of each NcGroup and populate the ncGroups container. + ncCheck(nc_inq_grps(myId, numgrps,&ncids[0]),__FILE__,__LINE__); + for(int i=0; i(tmpGroup.getName(),tmpGroup)); + } + } } // search in parent groups. @@ -319,13 +319,15 @@ multimap NcGroup::getVars(NcGroup::Location location) const { if((location == ParentsAndCurrent || location == ChildrenAndCurrent || location == Current || location ==All) && !tmpGroup.isNull()) { // get the number of variables. int varCount = getVarCount(); - // now get the name of each NcVar object and populate the ncVars container. - int* nvars=NULL; - vector varids(varCount); - ncCheck(nc_inq_varids(myId, nvars,&varids[0]),__FILE__,__LINE__); - for(int i=0; i(tmpVar.getName(),tmpVar)); + if (varCount){ + // now get the name of each NcVar object and populate the ncVars container. + int* nvars=NULL; + vector varids(varCount); + ncCheck(nc_inq_varids(myId, nvars,&varids[0]),__FILE__,__LINE__); + for(int i=0; i(tmpVar.getName(),tmpVar)); + } } } @@ -336,13 +338,15 @@ multimap NcGroup::getVars(NcGroup::Location location) const { while(!tmpGroup.isNull()) { // get the number of variables int varCount = tmpGroup.getVarCount(); - // now get the name of each NcVar object and populate the ncVars container. - int* nvars=NULL; - vector varids(varCount); - ncCheck(nc_inq_varids(tmpGroup.getId(), nvars,&varids[0]),__FILE__,__LINE__); - for(int i=0; i(tmpVar.getName(),tmpVar)); + if (varCount){ + // now get the name of each NcVar object and populate the ncVars container. + int* nvars=NULL; + vector varids(varCount); + ncCheck(nc_inq_varids(tmpGroup.getId(), nvars,&varids[0]),__FILE__,__LINE__); + for(int i=0; i(tmpVar.getName(),tmpVar)); + } } // continue loop with the parent. tmpGroup=tmpGroup.getParentGroup(); @@ -452,7 +456,8 @@ NcVar NcGroup::addVar(const string& name, const string& typeName, const vector NcGroup::getAtts(NcGroup::Location location) co int attCount = tmpGroup.getAttCount(); // now get the name of each NcAtt and populate the ncAtts container. for(int i=0; i(string(charName),tmpAtt)); + char charName[NC_MAX_NAME+1]; + ncCheck(nc_inq_attname(tmpGroup.getId(),NC_GLOBAL,i,charName),__FILE__,__LINE__); + NcGroupAtt tmpAtt(tmpGroup.getId(),i); + ncAtts.insert(pair(string(charName),tmpAtt)); } // continue loop with the parent. tmpGroup=tmpGroup.getParentGroup(); @@ -907,15 +912,15 @@ multimap NcGroup::getDims(NcGroup::Location location) const { // search in current group if(location == Current || location == ParentsAndCurrent || location == ChildrenAndCurrent || location == All ) { int dimCount = getDimCount(); - if (dimCount){ - vector dimids(dimCount); - ncCheck(nc_inq_dimids(getId(), &dimCount, &dimids[0], 0),__FILE__,__LINE__); - // now get the name of each NcDim and populate the nDims container. - for(int i=0; i(tmpDim.getName(),tmpDim)); - } - } + if (dimCount){ + vector dimids(dimCount); + ncCheck(nc_inq_dimids(getId(), &dimCount, &dimids[0], 0),__FILE__,__LINE__); + // now get the name of each NcDim and populate the nDims container. + for(int i=0; i(tmpDim.getName(),tmpDim)); + } + } } // search in parent groups. @@ -1048,11 +1053,13 @@ int NcGroup::getTypeCount(NcType::ncType enumType, NcGroup::Location location) c int ntypesp; int* typeidsp=NULL; ncCheck(nc_inq_typeids(getId(), &ntypesp,typeidsp),__FILE__,__LINE__); - vector typeids(ntypesp); - ncCheck(nc_inq_typeids(getId(), &ntypesp,&typeids[0]),__FILE__,__LINE__); - for (int i=0; i typeids(ntypesp); + ncCheck(nc_inq_typeids(getId(), &ntypesp,&typeids[0]),__FILE__,__LINE__); + for (int i=0; i NcGroup::getTypes(NcGroup::Location location) const { // search in current group if(location == Current || location == ParentsAndCurrent || location == ChildrenAndCurrent || location == All ) { int typeCount = getTypeCount(); - vector typeids(typeCount); - ncCheck(nc_inq_typeids(getId(), &typeCount,&typeids[0]),__FILE__,__LINE__); - // now get the name of each NcType and populate the nTypes container. - for(int i=0; i(tmpType.getName(),tmpType)); + if (typeCount){ + vector typeids(typeCount); + ncCheck(nc_inq_typeids(getId(), &typeCount,&typeids[0]),__FILE__,__LINE__); + // now get the name of each NcType and populate the nTypes container. + for(int i=0; i(tmpType.getName(),tmpType)); + } } }