[irstlm] 117/146: Updated 1002_fix_problems_identified_by_cppcheck.patch.

Giulio Paci giuliopaci-guest at moszumanska.debian.org
Tue May 17 07:37:15 UTC 2016


This is an automated email from the git hooks/post-receive script.

giuliopaci-guest pushed a commit to branch master
in repository irstlm.

commit 6a86b91adb4f0a06e4c489a8adb5548387f9d1a2
Author: Giulio Paci <giuliopaci at gmail.com>
Date:   Thu Apr 28 23:42:55 2016 +0200

    Updated 1002_fix_problems_identified_by_cppcheck.patch.
---
 .../1002_fix_problems_identified_by_cppcheck.patch | 307 +++------------------
 1 file changed, 31 insertions(+), 276 deletions(-)

diff --git a/debian/patches/1002_fix_problems_identified_by_cppcheck.patch b/debian/patches/1002_fix_problems_identified_by_cppcheck.patch
index 648c1a0..d6f0140 100644
--- a/debian/patches/1002_fix_problems_identified_by_cppcheck.patch
+++ b/debian/patches/1002_fix_problems_identified_by_cppcheck.patch
@@ -1,279 +1,34 @@
 Description: fix some problems reported by cppcheck
 Author: Giulio Paci <giuliopaci at gmail.com>
 Forwarded: yes
---- a/src/dictionary.cpp
-+++ b/src/dictionary.cpp
-@@ -192,6 +192,7 @@
-     cout << "\n";
-   }
-   cout << "*********************************************************\n";
-+  delete[] curve;
- }
- 
- //
-@@ -215,6 +216,7 @@
-   if (!inp) {
-     cerr << "cannot open test: " << filename << "\n";
-     //    print_curve(curvesize);
-+    delete[] OOVchart;
-     return NULL;
-   }
-   cerr << "test:";
-@@ -253,7 +255,7 @@
-   float* OOVrates = new float[curvesize];
-   for (int i=0; i<curvesize; i++)
-     OOVrates[i] = (float)OOVchart[i]/NwTest * 100.0;
--
-+  delete[] OOVchart;
-   return OOVrates;
- }
- 
---- a/src/lmInterpolation.cpp
-+++ b/src/lmInterpolation.cpp
-@@ -138,7 +138,7 @@
-   //checking the language model type
-   lmContainer* lmt=NULL;
- 
--  lmt = lmt->CreateLanguageModel(m_file[i],nlf,dlf);
-+  lmt = lmContainer::CreateLanguageModel(m_file[i],nlf,dlf);
- 
-   //let know that table has inverted n-grams
-   lmt->is_inverted(m_isinverted[i]);  //set inverted flag for each LM
-@@ -162,20 +162,13 @@
-   unsigned int _statesize=0,actualstatesize=0;
-   int _bol=0,actualbol=MAX_NGRAM;
-   double _bow=0.0,actualbow=0.0;
--//  bool _extendible=false,actualextendible=false;
--  bool* _extendible=NULL,actualextendible=false;
--
--  if (extendible) {
--    _extendible=new bool;
--    _extendible=false;
--  }
-+  bool _extendible=false,actualextendible=false;
- 
-   for (size_t i=0; i<m_lm.size(); i++) {
- 
-     ngram _ng(m_lm[i]->getDict());
-     _ng.trans(ng);
--//    _logpr=m_lm[i]->clprob(_ng,&_bow,&_bol,&_maxsuffptr,&_statesize,&_extendible);
--    _logpr=m_lm[i]->clprob(_ng,&_bow,&_bol,&_maxsuffptr,&_statesize,_extendible);
-+    _logpr=m_lm[i]->clprob(_ng,&_bow,&_bol,&_maxsuffptr,&_statesize,&_extendible);
-     //    assert(_statesize != InvalidContextLength);
- 
-     /*
-@@ -214,9 +207,8 @@
-   if (bow) *bow=log(actualbow);
-   if (maxsuffptr) *maxsuffptr=actualmaxsuffptr;
-   if (statesize) *statesize=actualstatesize;
--  if (extendible) {
-+  if (*extendible) {
-     *extendible=actualextendible;
--    delete _extendible;
-   }
- 
-   /*
---- a/src/lmclass.cpp
-+++ b/src/lmclass.cpp
-@@ -187,8 +187,17 @@
- {
-   if (MapScoreN > MaxMapSize) {
-     MaxMapSize=2*MapScoreN;
--    MapScore = (double*) realloc(MapScore, sizeof(double)*(MaxMapSize));
--    VERBOSE(2,"In lmclass::checkMap(...) MaxMapSize=" <<  MaxMapSize  << " MapScoreN=" <<  MapScoreN  << "\n");
-+    double* tmp = (double*) realloc(MapScore, sizeof(double)*(MaxMapSize));
-+    if( tmp != NULL )
-+    {
-+	    MapScore = tmp;
-+	    VERBOSE(2,"In lmclass::checkMap(...) MaxMapSize=" <<  MaxMapSize  << " MapScoreN=" <<  MapScoreN  << "\n");
-+    }
-+    else
-+    {
-+	    free(MapScore);
-+	    MapScore=NULL;
-+    }
-   }
- }
- 
---- a/src/mfstream.h
-+++ b/src/mfstream.h
-@@ -225,6 +225,7 @@
-       cerr << "close/open " << a <<"\n";
-       close();
-       open(a,ios::in);
-+      delete[] a;
-     } else
-       seekp(0);
- 
---- a/src/prune-lm.cpp
-+++ b/src/prune-lm.cpp
-@@ -68,6 +68,7 @@
-   thr[0]=0;
-   for(i=1,tk=strtok(s, ","); tk; tk=strtok(0, ","),i++) thr[i]=atof(tk);
-   for(; i<MAX_NGRAM; i++) thr[i]=thr[i-1];
-+  free(s);
- }
- 
- int main(int argc, char **argv)
---- a/src/util.cpp
-+++ b/src/util.cpp
-@@ -143,7 +143,7 @@
- 
- void *MMap(int	fd, int	access, off_t	offset, size_t	len, off_t	*gap)
- {
--  void	*p;
-+  void	*p=0;
-   int	pgsz,g=0;
- 
- #ifdef _WIN32
---- a/src/lmmacro.cpp
-+++ b/src/lmmacro.cpp
-@@ -222,12 +222,24 @@
- 
- 
-     if (microMacroMapN>0 && !(microMacroMapN % BUFSIZ)) {
--      microMacroMap = (int *)realloc(microMacroMap, sizeof(int)*(BUFSIZ*(1+microMacroMapN/BUFSIZ)));
-+      int* tmp = (int *)realloc(microMacroMap, sizeof(int)*(BUFSIZ*(1+microMacroMapN/BUFSIZ)));
-+      if( tmp == NULL ) {
-+	free(microMacroMap);
-+      }
-+      microMacroMap = tmp;
-       if (collapseFlag) {
-         //create supporting info for collapse
- 
--        collapsableMap = (bool *)realloc(collapsableMap, sizeof(bool)*(BUFSIZ*(1+microMacroMapN/BUFSIZ)));
--        collapsatorMap = (bool *)realloc(collapsatorMap, sizeof(bool)*(BUFSIZ*(1+microMacroMapN/BUFSIZ)));
-+        bool* tmp2 = (bool *)realloc(collapsableMap, sizeof(bool)*(BUFSIZ*(1+microMacroMapN/BUFSIZ)));
-+        if( tmp2 == NULL ) {
-+          free(collapsableMap);
-+        }
-+        collapsableMap = tmp2;
-+	tmp2 = (bool *)realloc(collapsatorMap, sizeof(bool)*(BUFSIZ*(1+microMacroMapN/BUFSIZ)));
-+        if( tmp2 == NULL ) {
-+          free(collapsatorMap);
-+        }
-+        collapsatorMap = tmp2;
-       }
-     }
-     microMacroMap[microMacroMapN] = lmtable::getDict()->getcode(macroW);
-@@ -269,16 +281,26 @@
-     // Add <s>-><s> to map if missing
-     if (!bos) {
-       getDict()->encode(BOS_);
--      if (microMacroMapN && !(microMacroMapN%BUFSIZ))
--        microMacroMap = (int *)realloc(microMacroMap, sizeof(int)*(microMacroMapN+BUFSIZ));
-+      if (microMacroMapN && !(microMacroMapN%BUFSIZ)) {
-+        int* tmp = (int *)realloc(microMacroMap, sizeof(int)*(microMacroMapN+BUFSIZ));
-+        if( tmp == NULL ) {
-+	  free(microMacroMap);
-+        }
-+        microMacroMap = tmp;
-+      }
-       microMacroMap[microMacroMapN++] = lmtable::getDict()->getcode(BOS_);
-     }
- 
-     // Add </s>-></s> to map if missing
-     if (!eos) {
-       getDict()->encode(EOS_);
--      if (microMacroMapN && !(microMacroMapN%BUFSIZ))
--        microMacroMap = (int *)realloc(microMacroMap, sizeof(int)*(microMacroMapN+BUFSIZ));
-+      if (microMacroMapN && !(microMacroMapN%BUFSIZ)) {
-+        int* tmp = (int *)realloc(microMacroMap, sizeof(int)*(microMacroMapN+BUFSIZ));
-+        if( tmp == NULL ) {
-+	  free(microMacroMap);
-+        }
-+        microMacroMap = tmp;
-+      }
-       microMacroMap[microMacroMapN++] = lmtable::getDict()->getcode(EOS_);
-     }
-   }
-@@ -856,7 +878,11 @@
-       if (wordCode>=lexicaltoken2classMapN) {
-         int r = (wordCode-lexicaltoken2classMapN)/BUFSIZ;
-         lexicaltoken2classMapN += (r+1)*BUFSIZ;
--        lexicaltoken2classMap = (int *)realloc(lexicaltoken2classMap, sizeof(int)*lexicaltoken2classMapN);
-+        int* tmp = (int *)realloc(lexicaltoken2classMap, sizeof(int)*lexicaltoken2classMapN);
-+        if( tmp == NULL ) {
-+	  free(lexicaltoken2classMap);
-+        }
-+	lexicaltoken2classMap = tmp;
-       }
-       lexicaltoken2classMap[wordCode] = classIdx;
-     }
---- a/src/compile-lm.cpp
-+++ b/src/compile-lm.cpp
-@@ -175,7 +175,7 @@
-   //checking the language model type
-   lmContainer* lmt=NULL;
- 
--  lmt = lmt->CreateLanguageModel(infile,ngramcache_load_factor,dictionary_load_factor);
-+  lmt = lmContainer::CreateLanguageModel(infile,ngramcache_load_factor,dictionary_load_factor);
- 
-   //let know that table has inverted n-grams
-   if (invert) lmt->is_inverted(invert);
---- a/src/interpolate-lm.cpp
-+++ b/src/interpolate-lm.cpp
-@@ -552,7 +552,7 @@
- {
-   lmContainer* lmt=NULL;
- 
--  lmt = lmt->CreateLanguageModel(file,nlf,dlf);
-+  lmt = lmContainer::CreateLanguageModel(file,nlf,dlf);
- 
-   lmt->setMaxLoadedLevel(requiredMaxlev);
- 
---- a/src/lmContainer.h
-+++ b/src/lmContainer.h
-@@ -139,7 +139,7 @@
-   inline int getLanguageModelType() {
-     return lmtype;
-   };
--  int getLanguageModelType(std::string filename);
-+  static int getLanguageModelType(std::string filename);
- 
-   inline virtual void dictionary_incflag(const bool flag) {
-     UNUSED(flag);
-@@ -147,8 +147,8 @@
- 
-   virtual bool filter(const string sfilter, lmContainer*& sublmt, const string skeepunigrams);
- 
--  lmContainer* CreateLanguageModel(const std::string infile, float nlf=0.0, float dlf=0.0);
--  lmContainer* CreateLanguageModel(int type, float nlf=0.0, float dlf=0.0);
-+  static lmContainer* CreateLanguageModel(const std::string infile, float nlf=0.0, float dlf=0.0);
-+  static lmContainer* CreateLanguageModel(int type, float nlf=0.0, float dlf=0.0);
- 
-   inline virtual bool is_OOV(int code) {
-     UNUSED(code);
---- a/src/plsa.cpp
-+++ b/src/plsa.cpp
-@@ -234,7 +234,7 @@
-     tc.train(adafile,it,.0);
-   }
-   if (strcmp(hfile,"hfff")==0)  system("rm -f hfff");
--  delete hfile;
-+  delete[] hfile;
- 	
-   exit(1);
- }
---- a/src/ngramtable.cpp
-+++ b/src/ngramtable.cpp
-@@ -526,7 +526,7 @@
- {
-   mfstream inp(filename,ios::in);
-   int i,c=0;
--  int selmask[MAX_NGRAM];
-+  int selmask[MAX_NGRAM] = { 0 };
- 
-   if (!inp) {
-     cerr << "cannot open " << filename << "\n";
---- a/src/ngt.cpp
-+++ b/src/ngt.cpp
-@@ -291,7 +291,7 @@
-          << " according to hmask\n";
- 
-     int i,c;
--    int selmask[MAX_NGRAM];
-+    int selmask[MAX_NGRAM] = { 0 };
- 
-     //parse hmask
-     i=0;
+--- a/src/mdiadapt.cpp
++++ b/src/mdiadapt.cpp
+@@ -1519,7 +1519,7 @@
+ 			system("date");
+ 			lmt->expand_level(i,numberofentries,filename,mmap);
+ 			
+-			double fstar,lambda,bo,dummy,dummy2,pr,ibow;
++			double fstar = 0.0,lambda,bo,dummy,dummy2,pr,ibow;
+ 			
+ 			ngram ng(dict,1);
+ 			ngram ng2(dict);
+@@ -1971,7 +1971,7 @@
+ 			
+ 			out << "\n\\" << i << "-grams:\n";
+ 			
+-			double fstar,lambda,bo,dummy,dummy2,pr,outLambda;
++			double fstar = 0.0,lambda,bo,dummy,dummy2,pr,outLambda;
+ 			
+ 			ngram ng(dict,1);
+ 			ngram ng2(dict);
+--- a/src/lmtable.cpp
++++ b/src/lmtable.cpp
+@@ -106,7 +106,7 @@
+ 		isInverted=false;
+ 		
+ 		//statistics
+-		for (int i=0; i<=LMTMAXLEV+1; i++) totget[i]=totbsearch[i]=0;
++		for (int i=0; i<LMTMAXLEV+1; i++) totget[i]=totbsearch[i]=0;
+ 		
+ 		logOOVpenalty=0.0; //penalty for OOV words (default 0)
+ 		

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/irstlm.git



More information about the debian-science-commits mailing list