Skip to content

Commit ed75598

Browse files
committed
expr2bits: bit strings for null pointers must have pointer width
The order of constructor arguments was wrong, resulting in 48 copies (the ASCII index of '0') instead of bit-width copies, being used.
1 parent e8ac4d6 commit ed75598

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/util/simplify_utils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ optionalt<exprt> bits2expr(
201201
type.id() == ID_c_bit_field || type.id() == ID_pointer ||
202202
type.id() == ID_bv || type.id() == ID_c_bool)
203203
{
204+
if(
205+
type.id() == ID_pointer && config.ansi_c.NULL_is_zero &&
206+
bits.find('1') == std::string::npos)
207+
{
208+
return null_pointer_exprt(to_pointer_type(type));
209+
}
210+
204211
endianness_mapt map(type, little_endian, ns);
205212

206213
std::string tmp = bits;
@@ -410,7 +417,7 @@ expr2bits(const exprt &expr, bool little_endian, const namespacet &ns)
410417
else if(type.id() == ID_pointer)
411418
{
412419
if(value == ID_NULL && config.ansi_c.NULL_is_zero)
413-
return std::string('0', to_bitvector_type(type).get_width());
420+
return std::string(to_bitvector_type(type).get_width(), '0');
414421
else
415422
return {};
416423
}

0 commit comments

Comments
 (0)