On 2015-02-06 00:56, Jeroen Vermeulen wrote:
> On 2015-02-05 17:25, Hieu Hoang wrote:
>> great, thanks. committed

Aaaand I found another one.  Wasn't grep'ing aggressively enough.  See
attachment.

As far as I can tell, this would also fix a crash in
PhraseDictionaryCompact::Load() if the filename is short.  The only
other change you might actually notice is a typo fix in the error
message: "exist" instead of "exit".  The logic for the optional suffix
becomes a bit simpler but should still work as it did.

The crash that this should fix is *not* the vector::_M_range_check crash
that's been reported.  That's actually what I was trying to figure out,
but it's got to be a std::vector::at() somewhere that's getting an
out-of-range index.  If a boost upgrade fixes that one, it may be a bug
in boost.  But it could also be because boost replaced an at() call with
array-style indexing, which doesn't check the index and may simply
address the wrong memory instead...


Jeroen
diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp
index 90d5575..9c3f6b5 100644
--- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp
+++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 #include <queue>
 #include <algorithm>
 #include <sys/stat.h>
+#include <boost/algorithm/string/predicate.hpp>
 
 #include "PhraseDictionaryCompact.h"
 #include "moses/FactorCollection.h"
@@ -37,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 #include "util/exception.hh"
 
 using namespace std;
+using namespace boost::algorithm;
 
 namespace Moses
 {
@@ -63,18 +65,9 @@ void PhraseDictionaryCompact::Load()
   std::string tFilePath = m_filePath;
 
   std::string suffix = ".minphr";
-  if(tFilePath.substr(tFilePath.length() - suffix.length(), suffix.length()) == suffix) {
-    if(!FileExists(tFilePath)) {
-      throw runtime_error("Error: File " + tFilePath + " does not exit.");
-      exit(1);
-    }
-  } else {
-    if(FileExists(tFilePath + suffix)) {
-      tFilePath += suffix;
-    } else {
-      throw runtime_error("Error: File " + tFilePath + ".minphr does not exit.");
-    }
-  }
+  if (!ends_with(tFilePath, suffix)) tFilePath += suffix;
+  if (!FileExists(tFilePath))
+    throw runtime_error("Error: File " + tFilePath + " does not exist.");
 
   m_phraseDecoder = new PhraseDecoder(*this, &m_input, &m_output,
                                       m_numScoreComponents, &m_weight);
_______________________________________________
Moses-support mailing list
[email protected]
http://mailman.mit.edu/mailman/listinfo/moses-support

Reply via email to