diff --git a/Geo/GModelIO_MSH.cpp b/Geo/GModelIO_MSH.cpp
index ace1af9d50113c3e4ccd04e131bfc8ee36df8fef..22ecb854d80c12e025e134734d595e52a180bc3c 100644
--- a/Geo/GModelIO_MSH.cpp
+++ b/Geo/GModelIO_MSH.cpp
@@ -526,9 +526,12 @@ int GModel::writeMSH(const std::string &name, double version, bool binary,
   if(numPhysicalNames()){
     fprintf(fp, "$PhysicalNames\n");
     fprintf(fp, "%d\n", numPhysicalNames());
-    for(piter it = firstPhysicalName(); it != lastPhysicalName(); it++)
+    for(piter it = firstPhysicalName(); it != lastPhysicalName(); it++){
+      std::string name = it->second;
+      if(name.size() > 254) name.resize(254);
       fprintf(fp, "%d %d \"%s\"\n", it->first.first, it->first.second,
-              it->second.c_str());
+              name.c_str());
+    }
     fprintf(fp, "$EndPhysicalNames\n");
   }
 
diff --git a/Geo/GModelIO_MSH2.cpp b/Geo/GModelIO_MSH2.cpp
index 560fbd83c43cffeb25e41e0c571d0db803da82b1..dd77c6a8e403b0302f4bbf18558877b55af42f9a 100644
--- a/Geo/GModelIO_MSH2.cpp
+++ b/Geo/GModelIO_MSH2.cpp
@@ -895,9 +895,12 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary,
     if(numPhysicalNames()){
       fprintf(fp, "$PhysicalNames\n");
       fprintf(fp, "%d\n", numPhysicalNames());
-      for(piter it = firstPhysicalName(); it != lastPhysicalName(); it++)
+      for(piter it = firstPhysicalName(); it != lastPhysicalName(); it++){
+        std::string name = it->second;
+        if(name.size() > 128) name.resize(128);
         fprintf(fp, "%d %d \"%s\"\n", it->first.first, it->first.second,
-                it->second.c_str());
+                name.c_str());
+      }
       fprintf(fp, "$EndPhysicalNames\n");
     }