From c7e86f519ce17c7df97e100070d2240c7e626c78 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Thu, 19 Nov 2015 09:23:16 +0100
Subject: [PATCH] proper check of indices in getter and setter of frequencies
 in HMMColumn

---
 modules/seq/base/src/hmm.cc | 16 ++++++++++++++++
 modules/seq/base/src/hmm.hh |  8 ++------
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/modules/seq/base/src/hmm.cc b/modules/seq/base/src/hmm.cc
index a89d3cf27..ef0ab66ca 100644
--- a/modules/seq/base/src/hmm.cc
+++ b/modules/seq/base/src/hmm.cc
@@ -60,6 +60,22 @@ Real HMMColumn::GetEntropy() const {
   return entropy;
 }
 
+Real HMMColumn::GetFreq(char ch) const{
+  int idx = this->GetIndex(ch);
+  if(idx == -1){
+    throw std::runtime_error("Invalid One Letter Code observed when getting frequency in HMMColumn!");
+  }
+  return freq_[idx];
+}
+
+void HMMColumn::SetFreq(char ch, Real freq){
+  int idx = this->GetIndex(ch);
+  if(idx == -1){
+    throw std::runtime_error("Invalid One Letter Code observed when setting frequency in HMMColumn!");
+  }
+  freq_[idx] = freq;
+}
+
 HMMPtr HMM::Load(const std::string& filename) {
   HMMPtr hmm(new HMM);
   boost::iostreams::filtering_stream<boost::iostreams::input> in;
diff --git a/modules/seq/base/src/hmm.hh b/modules/seq/base/src/hmm.hh
index 357fc7115..5fc755797 100644
--- a/modules/seq/base/src/hmm.hh
+++ b/modules/seq/base/src/hmm.hh
@@ -59,13 +59,9 @@ class HMMColumn {
 
   Real GetNEffDel() const { return n_eff_del_; }
 
-  Real GetFreq(char ch) const {
-    return freq_[this->GetIndex(ch)];
-  }
+  Real GetFreq(char ch) const;
 
-  void SetFreq(char ch, Real freq) {
-    freq_[this->GetIndex(ch)]=freq;
-  }
+  void SetFreq(char ch, Real freq);
 
   bool operator==(const HMMColumn& rhs) const {
     return !memcmp(freq_, rhs.freq_, sizeof(freq_)) &&
-- 
GitLab