Skip to content

Commit bbae82d

Browse files
Merge pull request #1183 from romainbrenguier/bugfix/character-digit#851
Adapt convert_digit_char for the case without radix argument
2 parents 3ab7e8b + 4928ef6 commit bbae82d

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
test.class
3+
--refine-strings
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
assertion at file test.java line 8 .* SUCCESS$
7+
assertion at file test.java line 10 .* FAILURE$
8+
--
9+
^warning: ignoring
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class test
2+
{
3+
4+
public static void main(String[] args)
5+
{
6+
char c = 'a';
7+
if(args.length>1)
8+
assert Character.getNumericValue(c) == 10;
9+
else
10+
assert Character.getNumericValue(c) != 10;
11+
}
12+
}

src/java_bytecode/character_refine_preprocess.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,22 @@ codet character_refine_preprocesst::convert_compare(conversion_inputt &target)
126126

127127

128128
/// Converts function call to an assignment of an expression corresponding to
129-
/// the java method Character.digit:(CI)I
129+
/// the java method Character.digit:(CI)I. The function call has one character
130+
/// argument and an optional integer radix argument. If the radix is not given
131+
/// it is set to 36 by default.
130132
/// \param target: a position in a goto program
133+
/// \return code assigning the result of the Character.digit function to the
134+
/// left-hand-side of the given target
131135
codet character_refine_preprocesst::convert_digit_char(
132136
conversion_inputt &target)
133137
{
134138
const code_function_callt &function_call=target;
135-
assert(function_call.arguments().size()==2);
139+
const std::size_t nb_args=function_call.arguments().size();
140+
PRECONDITION(nb_args==1 || nb_args==2);
136141
const exprt &arg=function_call.arguments()[0];
137-
const exprt &radix=function_call.arguments()[1];
142+
// If there is no radix argument we set it to 36 which is the maximum possible
143+
const exprt &radix=
144+
nb_args>1?function_call.arguments()[1]:from_integer(36, arg.type());
138145
const exprt &result=function_call.lhs();
139146
const typet &type=result.type();
140147

0 commit comments

Comments
 (0)