Skip to content

Commit 6982772

Browse files
committed
Do not unnecessarily use C string functions
1 parent 73e0c0f commit 6982772

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/goto-programs/interpreter_evaluate.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,11 @@ void interpretert::evaluate(
389389
}
390390
else if(expr.type().id()==ID_string)
391391
{
392-
irep_idt value=to_constant_expr(expr).get_value();
393-
const char *str=value.c_str();
394-
std::size_t length=strlen(str)+1;
392+
const std::string &value = id2string(to_constant_expr(expr).get_value());
395393
if(show)
396394
warning() << "string decoding not fully implemented "
397-
<< length << eom;
398-
mp_integer tmp = get_string_container()[id2string(value)];
399-
dest.push_back(tmp);
395+
<< value.size() + 1 << eom;
396+
dest.push_back(get_string_container()[value]);
400397
return;
401398
}
402399
else

src/goto-programs/string_abstraction.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,11 @@ bool string_abstractiont::build(const exprt &object, exprt &dest, bool write)
759759

760760
if(object.id()==ID_string_constant)
761761
{
762-
mp_integer str_len=strlen(object.get(ID_value).c_str());
762+
const std::string &str_value = id2string(object.get(ID_value));
763+
// make sure we handle the case of a string constant with string-terminating
764+
// \0 in it
765+
const std::size_t str_len =
766+
std::min(str_value.size(), str_value.find('\0'));
763767
return build_symbol_constant(str_len, str_len+1, dest);
764768
}
765769

0 commit comments

Comments
 (0)