@@ -132,9 +132,10 @@ class java_bytecode_parsert final : public parsert
132
132
T read ()
133
133
{
134
134
static_assert (
135
- std::is_unsigned<T>::value, " T should be an unsigned integer" );
135
+ std::is_unsigned<T>::value || std::is_signed<T>::value,
136
+ " T should be a signed or unsigned integer" );
136
137
const constexpr size_t bytes = sizeof (T);
137
- u8 result = 0 ;
138
+ T result = 0 ;
138
139
for (size_t i = 0 ; i < bytes; i++)
139
140
{
140
141
if (!*in)
@@ -145,7 +146,7 @@ class java_bytecode_parsert final : public parsert
145
146
result <<= 8u ;
146
147
result |= static_cast <u1>(in->get ());
147
148
}
148
- return narrow_cast<T>( result) ;
149
+ return result;
149
150
}
150
151
151
152
void store_unknown_method_handle (size_t bootstrap_method_index);
@@ -700,7 +701,7 @@ void java_bytecode_parsert::rconstant_pool()
700
701
std::string s;
701
702
s.resize (bytes);
702
703
for (auto &ch : s)
703
- ch = read <u1 >();
704
+ ch = read <std::string::value_type >();
704
705
it->s = s; // Add to string table
705
706
}
706
707
break ;
@@ -942,15 +943,15 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
942
943
943
944
case ' b' : // a signed byte
944
945
{
945
- const s1 c = read <u1 >();
946
+ const s1 c = read <s1 >();
946
947
instruction.args .push_back (from_integer (c, signedbv_typet (8 )));
947
948
}
948
949
address+=1 ;
949
950
break ;
950
951
951
952
case ' o' : // two byte branch offset, signed
952
953
{
953
- const s2 offset = read <u2 >();
954
+ const s2 offset = read <s2 >();
954
955
// By converting the signed offset into an absolute address (by adding
955
956
// the current address) the number represented becomes unsigned.
956
957
instruction.args .push_back (
@@ -961,7 +962,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
961
962
962
963
case ' O' : // four byte branch offset, signed
963
964
{
964
- const s4 offset = read <u4 >();
965
+ const s4 offset = read <s4 >();
965
966
// By converting the signed offset into an absolute address (by adding
966
967
// the current address) the number represented becomes unsigned.
967
968
instruction.args .push_back (
@@ -994,15 +995,15 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
994
995
{
995
996
const u2 v = read <u2>();
996
997
instruction.args .push_back (from_integer (v, unsignedbv_typet (16 )));
997
- const s2 c = read <u2 >();
998
+ const s2 c = read <s2 >();
998
999
instruction.args .push_back (from_integer (c, signedbv_typet (16 )));
999
1000
address+=4 ;
1000
1001
}
1001
1002
else // local variable index (one byte) plus one signed byte
1002
1003
{
1003
1004
const u1 v = read <u1>();
1004
1005
instruction.args .push_back (from_integer (v, unsignedbv_typet (8 )));
1005
- const s1 c = read <u1 >();
1006
+ const s1 c = read <s1 >();
1006
1007
instruction.args .push_back (from_integer (c, signedbv_typet (8 )));
1007
1008
address+=2 ;
1008
1009
}
@@ -1032,7 +1033,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
1032
1033
}
1033
1034
1034
1035
// now default value
1035
- const s4 default_value = read <u4 >();
1036
+ const s4 default_value = read <s4 >();
1036
1037
// By converting the signed offset into an absolute address (by adding
1037
1038
// the current address) the number represented becomes unsigned.
1038
1039
instruction.args .push_back (
@@ -1045,8 +1046,8 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
1045
1046
1046
1047
for (std::size_t i=0 ; i<npairs; i++)
1047
1048
{
1048
- const s4 match = read <u4 >();
1049
- const s4 offset = read <u4 >();
1049
+ const s4 match = read <s4 >();
1050
+ const s4 offset = read <s4 >();
1050
1051
instruction.args .push_back (
1051
1052
from_integer (match, signedbv_typet (32 )));
1052
1053
// By converting the signed offset into an absolute address (by adding
@@ -1070,23 +1071,23 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
1070
1071
}
1071
1072
1072
1073
// now default value
1073
- const s4 default_value = read <u4 >();
1074
+ const s4 default_value = read <s4 >();
1074
1075
instruction.args .push_back (
1075
1076
from_integer (base_offset+default_value, signedbv_typet (32 )));
1076
1077
address+=4 ;
1077
1078
1078
1079
// now low value
1079
- const s4 low_value = read <u4 >();
1080
+ const s4 low_value = read <s4 >();
1080
1081
address+=4 ;
1081
1082
1082
1083
// now high value
1083
- const s4 high_value = read <u4 >();
1084
+ const s4 high_value = read <s4 >();
1084
1085
address+=4 ;
1085
1086
1086
1087
// there are high-low+1 offsets, and they are signed
1087
1088
for (s4 i=low_value; i<=high_value; i++)
1088
1089
{
1089
- s4 offset = read <u4 >();
1090
+ s4 offset = read <s4 >();
1090
1091
instruction.args .push_back (from_integer (i, signedbv_typet (32 )));
1091
1092
// By converting the signed offset into an absolute address (by adding
1092
1093
// the current address) the number represented becomes unsigned.
@@ -1130,7 +1131,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
1130
1131
1131
1132
case ' s' : // a signed short
1132
1133
{
1133
- const s2 s = read <u2 >();
1134
+ const s2 s = read <s2 >();
1134
1135
instruction.args .push_back (from_integer (s, signedbv_typet (16 )));
1135
1136
}
1136
1137
address+=2 ;
0 commit comments