Skip to content

Commit 4031eac

Browse files
committed
Non-negative array/vector sizes are invariants
1 parent cf41a88 commit 4031eac

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/util/expr_initializer.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include "c_types.h"
1616
#include "format_expr.h"
1717
#include "format_type.h"
18+
#include "invariant.h"
1819
#include "message.h"
1920
#include "namespace.h"
2021
#include "pointer_offset_size.h"
@@ -173,12 +174,8 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
173174
throw 0;
174175
}
175176

176-
if(array_size<0)
177-
{
178-
error().source_location=source_location;
179-
error() << "failed to initialize array with negative size" << eom;
180-
throw 0;
181-
}
177+
DATA_INVARIANT(
178+
array_size >= 0, "array should not have negative size");
182179

183180
array_exprt value(array_type);
184181
value.operands().resize(integer2unsigned(array_size), tmpval);
@@ -209,12 +206,8 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
209206
throw 0;
210207
}
211208

212-
if(vector_size<0)
213-
{
214-
error().source_location=source_location;
215-
error() << "failed to initialize vector with negative size" << eom;
216-
throw 0;
217-
}
209+
DATA_INVARIANT(
210+
vector_size >= 0, "vector should not have negative size");
218211

219212
vector_exprt value(vector_type);
220213
value.operands().resize(integer2unsigned(vector_size), tmpval);

0 commit comments

Comments
 (0)