[MOAB-dev] commit/MOAB: danwu: Thanks for Jayesh Krishna to point out this bug. In NCHelperEuler.cpp and NCHelperFV.cpp, ss_tag_name.clear() does not empty the string (it just clears the eof flag on the string). One possible solution is to use the str("") gimmick, so that we can still reuse the same stringstream object. We pick another solution that moves the definition of ss_tag_name inside the loops, so we do not clear anymore, and the code will be easier to understand.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Oct 24 11:29:18 CDT 2013


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/e7850db9a0b6/
Changeset:   e7850db9a0b6
Branch:      master
User:        danwu
Date:        2013-10-24 18:28:26
Summary:     Thanks for Jayesh Krishna to point out this bug. In NCHelperEuler.cpp and NCHelperFV.cpp, ss_tag_name.clear() does not empty the string (it just clears the eof flag on the string). One possible solution is to use the str("") gimmick, so that we can still reuse the same stringstream object. We pick another solution that moves the definition of ss_tag_name inside the loops, so we do not clear anymore, and the code will be easier to understand.

Affected #:  2 files

diff --git a/src/io/NCHelperEuler.cpp b/src/io/NCHelperEuler.cpp
index ca86127..5b1d052 100644
--- a/src/io/NCHelperEuler.cpp
+++ b/src/io/NCHelperEuler.cpp
@@ -332,7 +332,6 @@ ErrorCode NCHelperEuler::init_mesh_vals()
   ijdimNames[0] = "__lon";
   ijdimNames[1] = "__lat";
 
-  std::stringstream ss_tag_name;
   std::string tag_name;
   Tag tagh;
 
@@ -347,7 +346,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       val[0] = lCDims[1];
       val[1] = lCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -392,7 +391,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
         ERRORR(MB_FAILURE, "Unrecognized data type");
         break;
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_VALS";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
@@ -414,7 +413,7 @@ ErrorCode NCHelperEuler::init_mesh_vals()
       val[0] = gCDims[1];
       val[1] = gCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);

diff --git a/src/io/NCHelperFV.cpp b/src/io/NCHelperFV.cpp
index a234450..7f4142e 100644
--- a/src/io/NCHelperFV.cpp
+++ b/src/io/NCHelperFV.cpp
@@ -336,7 +336,6 @@ ErrorCode NCHelperFV::init_mesh_vals()
   ijdimNames[2] = "__lon";
   ijdimNames[3] = "__lat";
 
-  std::stringstream ss_tag_name;
   std::string tag_name;
   Tag tagh;
 
@@ -359,7 +358,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
       val[0] = lCDims[1];
       val[1] = lCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);
@@ -412,7 +411,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
         ERRORR(MB_FAILURE, "Unrecognized data type");
         break;
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_LOC_VALS";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 0, data_type, tagh, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN);
@@ -442,7 +441,7 @@ ErrorCode NCHelperFV::init_mesh_vals()
       val[0] = gCDims[1];
       val[1] = gCDims[4];
     }
-    ss_tag_name.clear();
+    std::stringstream ss_tag_name;
     ss_tag_name << ijdimNames[i] << "_GLOBAL_MINMAX";
     tag_name = ss_tag_name.str();
     rval = mbImpl->tag_get_handle(tag_name.c_str(), 2, MB_TYPE_INTEGER, tagh, MB_TAG_SPARSE | MB_TAG_CREAT);

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list