From: Anthony Geay Date: Fri, 17 Feb 2017 15:50:30 +0000 (+0100) Subject: Protection against agressive users X-Git-Tag: V8_3_0a2~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=51532a02a1ba88db715d40b0f120977d7218c693;p=tools%2Fmedcoupling.git Protection against agressive users --- diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.cxx b/src/MEDLoader/MEDFileBlowStrEltUp.cxx index 973f2b8ed..9e6ee4f45 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.cxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.cxx @@ -803,6 +803,23 @@ void LocSpliter::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDis _fw->newPerMeshPerTypePerDisc(pmptpd); } +void MEDFileBlowStrEltUp::DealWithConflictNames(MEDFileAnyTypeFieldMultiTS *fmtsToAdd, const MEDFileFields *fs) +{ + std::vector fnames(fs->getFieldsNames()); + for(int i=0;i<1000;i++) + { + std::ostringstream oss; oss << fmtsToAdd->getName(); + if(i>=1) + oss << "_" << i-1; + if(std::find(fnames.begin(),fnames.end(),oss.str())==fnames.end()) + { + fmtsToAdd->setName(oss.str()); + return ; + } + } + throw INTERP_KERNEL::Exception("DealWithConflictNames : Eh eh interesting !"); +} + MCAuto MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, MEDFileMeshes *msOut, MEDFileFields *allZeOutFields) { LocSpliter ls(fields); @@ -815,6 +832,7 @@ MCAuto MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields for(int j=0;j<(*it)->getNumberOfFields();j++) { MCAuto fmts((*it)->getFieldAtPos(j)); + DealWithConflictNames(fmts,allZeOutFields); allZeOutFields->pushField(fmts); } } diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.hxx b/src/MEDLoader/MEDFileBlowStrEltUp.hxx index 1363548de..487583920 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.hxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.hxx @@ -45,6 +45,7 @@ namespace MEDCoupling void dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const; static std::string BuildNewMeshName(const std::string& meshName, const std::string& seName); static std::string BuildVarAttName(std::size_t iPart, std::size_t totINbParts, std::size_t jPart, std::size_t totJNbParts, const std::string& name); + static void DealWithConflictNames(MEDFileAnyTypeFieldMultiTS *fmtsToAdd, const MEDFileFields *fs); public: static const char MED_BALL_STR[]; private: