[irstlm] 74/146: Added 1002_fix_problems_identified_by_cppcheck.patch.
Giulio Paci
giuliopaci-guest at moszumanska.debian.org
Tue May 17 07:37:09 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 b48ef9ef5d7c3675e9764bc97d5cfbb8511fb518
Author: Giulio Paci <giuliopaci at gmail.com>
Date: Sun Jan 27 03:20:08 2013 +0100
Added 1002_fix_problems_identified_by_cppcheck.patch.
---
.../1002_fix_problems_identified_by_cppcheck.patch | 257 +++++++++++++++++++++
1 file changed, 257 insertions(+)
diff --git a/debian/patches/1002_fix_problems_identified_by_cppcheck.patch b/debian/patches/1002_fix_problems_identified_by_cppcheck.patch
new file mode 100644
index 0000000..d8a15ca
--- /dev/null
+++ b/debian/patches/1002_fix_problems_identified_by_cppcheck.patch
@@ -0,0 +1,257 @@
+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
+@@ -221,6 +221,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
+@@ -113,6 +113,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, const char **argv)
+--- a/src/util.cpp
++++ b/src/util.cpp
+@@ -131,7 +131,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
+@@ -232,7 +232,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
+@@ -599,7 +599,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
+@@ -250,7 +250,7 @@
+ tc.train(adafile,it,.0);
+ }
+ if (strcmp(hfile,"hfff")==0) system("rm -f hfff");
+- delete hfile;
++ delete[] hfile;
+
+ exit(1);
+ }
--
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