Skip to content

Commit ef55de1

Browse files
committed
fix out of bounds bug
Signed-off-by: Lev Nachmanson <[email protected]>
1 parent 3990df6 commit ef55de1

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/math/lp/dioph_eq.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace lp {
6363
return m_rev_map.find(b)->second;
6464
}
6565

66-
unsigned size() const {return m_map.size();}
66+
unsigned size() const {return static_cast<unsigned>(m_map.size());}
6767

6868
void erase_val(unsigned b) {
6969
SASSERT(contains(m_rev_map, b) && contains(m_map, m_rev_map[b]));
@@ -340,7 +340,7 @@ namespace lp {
340340
TRACE("d_undo", tout << "t:"<< t<<", t->j():"<< t->j() << std::endl;);
341341
TRACE("dioph_eq", lra.print_term(*t, tout); tout << ", t->j() =" << t->j() << std::endl;);
342342
if (!contains(m_active_terms, t)) {
343-
for (int i = m_added_terms.size() - 1; i >= 0; --i) {
343+
for (int i = static_cast<int>(m_added_terms.size() - 1); i >= 0; --i) {
344344
if (m_added_terms[i] != t) continue;
345345
if ((unsigned)i != m_added_terms.size() -1)
346346
m_added_terms[i] = m_added_terms.back();
@@ -388,7 +388,7 @@ namespace lp {
388388
};
389389

390390
void remove_last_entry() {
391-
unsigned ei = m_entries.size() - 1;
391+
unsigned ei = static_cast<unsigned>(m_entries.size() - 1);
392392

393393
if (m_k2s.has_val(ei)) {
394394
remove_from_S(ei);
@@ -487,7 +487,7 @@ namespace lp {
487487

488488
void remove_last_row_in_matrix(static_matrix<mpq, mpq>& m) {
489489
auto & last_row = m.m_rows.back();
490-
for (unsigned k = last_row.size(); k-- > 0;) {
490+
for (unsigned k = static_cast<unsigned>(last_row.size()); k-- > 0;) {
491491
m.remove_element(last_row, last_row[k]);
492492
}
493493
m.m_rows.pop_back();
@@ -609,6 +609,7 @@ namespace lp {
609609
SASSERT(entry_invariant(entry_index));
610610
}
611611
void subs_entry(unsigned ei) {
612+
if (ei >= m_entries.size()) return;
612613
std::queue<unsigned> q;
613614
for (const auto& p: m_e_matrix.m_rows[ei]) {
614615
if (can_substitute(p.var()))
@@ -754,9 +755,9 @@ namespace lp {
754755
fresh_entries_to_remove.pop_back();
755756
const fresh_definition & fd = m_fresh_definitions[xt];
756757
TRACE("d_once", print_entry(fd.m_ei, tout) << std::endl; tout << "xt:" << xt << std::endl;);
757-
unsigned last_ei = m_entries.size() - 1;
758+
unsigned last_ei = static_cast<unsigned>(m_entries.size() - 1);
758759
if (fd.m_ei != last_ei) { // not the last entry
759-
transpose_entries(fd.m_ei, m_entries.size() -1 );
760+
transpose_entries(fd.m_ei, static_cast<unsigned>(m_entries.size() - 1));
760761
// we are not going to recalculate fd.m_ei
761762
// but we might need to recalculate last_ei, which becomes fd.m_ei
762763
if (contains(entries_to_recalculate, last_ei )) {
@@ -1786,7 +1787,7 @@ namespace lp {
17861787
pivot_col_cell_index;
17871788
}
17881789

1789-
unsigned cell_to_process = column.size() - 1;
1790+
unsigned cell_to_process = static_cast<unsigned>(column.size() - 1);
17901791
while (cell_to_process > 0) {
17911792
auto& c = column[cell_to_process];
17921793
if (belongs_to_s(c.var())) {

src/math/lp/indexed_vector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class indexed_vector {
8080

8181
void resize(unsigned data_size);
8282
unsigned data_size() const {
83-
return m_data.size();
83+
return static_cast<unsigned>(m_data.size());
8484
}
8585

8686
unsigned size() const {

src/math/lp/indexed_vector_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void indexed_vector<T>::clear() {
5151
}
5252
template <typename T>
5353
void indexed_vector<T>::clear_all() {
54-
unsigned i = m_data.size();
54+
unsigned i = static_cast<unsigned>(m_data.size());
5555
while (i--) m_data[i] = numeric_traits<T>::zero();
5656
m_index.resize(0);
5757
}

0 commit comments

Comments
 (0)