Skip to content

Commit 6440fc2

Browse files
peterschrammelkroening
authored andcommitted
Replace asserts
1 parent 2655d98 commit 6440fc2

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/goto-instrument/accelerate/trace_automaton.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Author: Matt Lewis
1515
#include <iostream>
1616
#include <limits>
1717

18+
#include <util/invariant.h>
19+
1820
#include "path.h"
1921

2022
const statet automatont::no_state=std::numeric_limits<statet>::max();
@@ -137,7 +139,9 @@ void trace_automatont::determinise()
137139
{
138140
state_sett t;
139141
pop_unmarked_dstate(t);
140-
assert(find_dstate(t)!=automatont::no_state);
142+
INVARIANT(
143+
find_dstate(t)!=automatont::no_state,
144+
"Removed state has actually been removed");
141145

142146

143147
// For each symbol a such that there is a transition
@@ -237,8 +241,9 @@ statet trace_automatont::add_dstate(state_sett &s)
237241
state_num=dta.add_state();
238242
dstates[s]=state_num;
239243
unmarked_dstates.push_back(s);
240-
241-
assert(dstates.find(s)!=dstates.end());
244+
INVARIANT(
245+
dstates.find(s)!=dstates.end(),
246+
"Added state has actually been added");
242247

243248
for(state_sett::iterator it=s.begin();
244249
it!=s.end();
@@ -290,7 +295,7 @@ statet automatont::add_state()
290295
*/
291296
void automatont::add_trans(statet s, goto_programt::targett a, statet t)
292297
{
293-
assert(s<transitions.size());
298+
PRECONDITION(s<transitions.size());
294299
transitionst &trans=transitions[s];
295300

296301
trans.insert(std::make_pair(a, t));
@@ -305,17 +310,17 @@ void trace_automatont::add_dtrans(
305310
state_sett &t)
306311
{
307312
statet sidx=find_dstate(s);
308-
statet tidx=find_dstate(t);
313+
CHECK_RETURN(sidx!=automatont::no_state);
309314

310-
assert(sidx!=automatont::no_state);
311-
assert(tidx!=automatont::no_state);
315+
statet tidx=find_dstate(t);
316+
CHECK_RETURN(tidx!=automatont::no_state);
312317

313318
dta.add_trans(sidx, a, tidx);
314319
}
315320

316321
void automatont::move(statet s, goto_programt::targett a, state_sett &t)
317322
{
318-
assert(s<transitions.size());
323+
PRECONDITION(s<transitions.size());
319324

320325
transitionst &trans=transitions[s];
321326

src/util/string2int.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Author: Michael Tautschnig, [email protected]
1111
#include <cerrno>
1212
#include <cstdlib>
1313
#include <limits>
14-
#include <cassert>
14+
15+
#include "invariant.h"
1516

1617
template <typename T>
1718
inline T str2number(const char *str, int base, bool safe)
@@ -28,22 +29,22 @@ inline T str2number(const char *str, int base, bool safe)
2829

2930
if(safe)
3031
{
31-
assert(0==errno);
32+
CHECK_RETURN(0==errno);
3233
errno=errno_bak;
33-
assert(endptr!=str);
34+
CHECK_RETURN(endptr!=str);
3435
if(std::numeric_limits<T>::min()==0)
3536
{
3637
// unsigned
37-
assert(val>=0);
38-
assert(
38+
CHECK_RETURN(val>=0);
39+
CHECK_RETURN(
3940
(unsigned long long)(T)val<=
4041
(unsigned long long)std::numeric_limits<T>::max());
4142
}
4243
else
4344
{
4445
// signed
45-
assert(val<=(long long)std::numeric_limits<T>::max());
46-
assert(val>=(long long)std::numeric_limits<T>::min());
46+
CHECK_RETURN(val<=(long long)std::numeric_limits<T>::max());
47+
CHECK_RETURN(val>=(long long)std::numeric_limits<T>::min());
4748
}
4849
}
4950

0 commit comments

Comments
 (0)