From 51532a02a1ba88db715d40b0f120977d7218c693 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 17 Feb 2017 16:50:30 +0100 Subject: [PATCH] Protection against agressive users --- src/MEDLoader/MEDFileBlowStrEltUp.cxx | 18 ++++++++++++++++++ src/MEDLoader/MEDFileBlowStrEltUp.hxx | 1 + 2 files changed, 19 insertions(+) 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: -- 2.39.2