Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTetsuo Kiso <tetsuo-s@is.naist.jp>2012-05-07 20:13:31 +0400
committerTetsuo Kiso <tetsuo-s@is.naist.jp>2012-05-07 20:13:31 +0400
commite2f01d74515baebc6d79c7524991dcb4c0a75a56 (patch)
treef520221c5426e0e8cce2c89a264173679abacb90 /scripts/ems
parent9cd8e0ce5fae6a2f2f07908d98729a1984678c92 (diff)
No copying allowed.
Check the return values of calloc().
Diffstat (limited to 'scripts/ems')
-rw-r--r--scripts/ems/biconcor/Alignment.h4
-rw-r--r--scripts/ems/biconcor/Mismatch.h4
-rw-r--r--scripts/ems/biconcor/PhrasePairCollection.h4
-rw-r--r--scripts/ems/biconcor/SuffixArray.h4
-rw-r--r--scripts/ems/biconcor/TargetCorpus.cpp41
-rw-r--r--scripts/ems/biconcor/TargetCorpus.h5
6 files changed, 56 insertions, 6 deletions
diff --git a/scripts/ems/biconcor/Alignment.h b/scripts/ems/biconcor/Alignment.h
index f6e448047..5927388c7 100644
--- a/scripts/ems/biconcor/Alignment.h
+++ b/scripts/ems/biconcor/Alignment.h
@@ -14,6 +14,10 @@ private:
INDEX m_sentenceCount;
char m_unaligned[ 256 ]; // here for speed (local to PhraseAlignment)
+ // No copying allowed.
+ Alignment(const Alignment&);
+ void operator=(const Alignment&);
+
public:
Alignment();
~Alignment();
diff --git a/scripts/ems/biconcor/Mismatch.h b/scripts/ems/biconcor/Mismatch.h
index 4a54a6342..f08fc282a 100644
--- a/scripts/ems/biconcor/Mismatch.h
+++ b/scripts/ems/biconcor/Mismatch.h
@@ -26,6 +26,10 @@ private:
bool m_target_unaligned[ 256 ];
bool m_unaligned;
+ // No copying allowed.
+ Mismatch(const Mismatch&);
+ void operator=(const Mismatch&);
+
public:
Mismatch( SuffixArray *sa, TargetCorpus *tc, Alignment *a, INDEX sentence_id, INDEX position, char source_length, char target_length, char source_start, char source_end );
~Mismatch();
diff --git a/scripts/ems/biconcor/PhrasePairCollection.h b/scripts/ems/biconcor/PhrasePairCollection.h
index 2708d4c93..f88bfc10f 100644
--- a/scripts/ems/biconcor/PhrasePairCollection.h
+++ b/scripts/ems/biconcor/PhrasePairCollection.h
@@ -25,6 +25,10 @@ private:
int m_max_pp_target;
int m_max_pp;
+ // No copying allowed.
+ PhrasePairCollection(const PhrasePairCollection&);
+ void operator=(const PhrasePairCollection&);
+
public:
PhrasePairCollection ( SuffixArray *, TargetCorpus *, Alignment * );
~PhrasePairCollection ();
diff --git a/scripts/ems/biconcor/SuffixArray.h b/scripts/ems/biconcor/SuffixArray.h
index 6ac77baa4..af7f5567e 100644
--- a/scripts/ems/biconcor/SuffixArray.h
+++ b/scripts/ems/biconcor/SuffixArray.h
@@ -19,6 +19,10 @@ private:
INDEX m_size;
INDEX m_sentenceCount;
+ // No copying allowed.
+ SuffixArray(const SuffixArray&);
+ void operator=(const SuffixArray&);
+
public:
SuffixArray();
~SuffixArray();
diff --git a/scripts/ems/biconcor/TargetCorpus.cpp b/scripts/ems/biconcor/TargetCorpus.cpp
index fa09be3bd..9230cd673 100644
--- a/scripts/ems/biconcor/TargetCorpus.cpp
+++ b/scripts/ems/biconcor/TargetCorpus.cpp
@@ -13,6 +13,19 @@ const int LINE_MAX_LENGTH = 10000;
using namespace std;
+TargetCorpus::TargetCorpus()
+ : m_array(NULL),
+ m_sentenceEnd(NULL),
+ m_vcb(),
+ m_size(0),
+ m_sentenceCount(0) {}
+
+TargetCorpus::~TargetCorpus()
+{
+ free(m_array);
+ free(m_sentenceEnd);
+}
+
void TargetCorpus::Create(const string& fileName )
{
ifstream textFile;
@@ -43,6 +56,16 @@ void TargetCorpus::Create(const string& fileName )
m_array = (WORD_ID*) calloc( sizeof( WORD_ID ), m_size );
m_sentenceEnd = (INDEX*) calloc( sizeof( INDEX ), m_sentenceCount );
+ if (m_array == NULL) {
+ cerr << "cannot allocate memory to m_array" << endl;
+ exit(1);
+ }
+
+ if (m_sentenceEnd == NULL) {
+ cerr << "cannot allocate memory to m_sentenceEnd" << endl;
+ exit(1);
+ }
+
// fill the array
int wordIndex = 0;
int sentenceId = 0;
@@ -69,12 +92,6 @@ void TargetCorpus::Create(const string& fileName )
cerr << "done reading " << wordIndex << " words, " << sentenceId << " sentences." << endl;
}
-TargetCorpus::~TargetCorpus()
-{
- free(m_array);
- free(m_sentenceEnd);
-}
-
WORD TargetCorpus::GetWordFromId( const WORD_ID id ) const
{
return m_vcb.GetWord( id );
@@ -132,11 +149,23 @@ void TargetCorpus::Load(const string& fileName )
fread( &m_size, sizeof(INDEX), 1, pFile );
cerr << "words in corpus: " << m_size << endl;
m_array = (WORD_ID*) calloc( sizeof(WORD_ID), m_size );
+
+ if (m_array == NULL) {
+ cerr << "cannot allocate memory to m_array" << endl;
+ exit(1);
+ }
+
fread( m_array, sizeof(WORD_ID), m_size, pFile ); // corpus
fread( &m_sentenceCount, sizeof(INDEX), 1, pFile );
cerr << "sentences in corpus: " << m_sentenceCount << endl;
m_sentenceEnd = (INDEX*) calloc( sizeof(INDEX), m_sentenceCount );
+
+ if (m_sentenceEnd == NULL) {
+ cerr << "cannot allocate memory to m_sentenceEnd" << endl;
+ exit(1);
+ }
+
fread( m_sentenceEnd, sizeof(INDEX), m_sentenceCount, pFile); // sentence index
fclose( pFile );
m_vcb.Load( fileName + ".tgt-vcb" );
diff --git a/scripts/ems/biconcor/TargetCorpus.h b/scripts/ems/biconcor/TargetCorpus.h
index ea3e6363f..24b6a00ec 100644
--- a/scripts/ems/biconcor/TargetCorpus.h
+++ b/scripts/ems/biconcor/TargetCorpus.h
@@ -14,7 +14,12 @@ private:
INDEX m_size;
INDEX m_sentenceCount;
+ // No copying allowed.
+ TargetCorpus(const TargetCorpus&);
+ void operator=(const TargetCorpus&);
+
public:
+ TargetCorpus();
~TargetCorpus();
void Create(const std::string& fileName );