Skip to content

Commit 139c411

Browse files
Fix code issues causing warnings in CLion IDE
Mostly relate to signed/unsigned mismatch and passing as const reference
1 parent 04d30bd commit 139c411

File tree

1 file changed

+48
-50
lines changed

1 file changed

+48
-50
lines changed

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class java_bytecode_parsert final : public parsert
142142
error() << "unexpected end of bytecode file" << eom;
143143
throw 0;
144144
}
145-
result <<= 8;
146-
result |= in->get();
145+
result <<= 8u;
146+
result |= static_cast<u1>(in->get());
147147
}
148148
return narrow_cast<T>(result);
149149
}
@@ -185,7 +185,7 @@ class structured_pool_entryt
185185
using pool_entryt = java_bytecode_parsert::pool_entryt;
186186
using pool_entry_lookupt = std::function<pool_entryt &(u2)>;
187187

188-
explicit structured_pool_entryt(pool_entryt entry) : tag(entry.tag)
188+
explicit structured_pool_entryt(const pool_entryt &entry) : tag(entry.tag)
189189
{
190190
}
191191

@@ -217,7 +217,7 @@ class class_infot : public structured_pool_entryt
217217
name_index = entry.ref1;
218218
}
219219

220-
std::string get_name(pool_entry_lookupt pool_entry) const
220+
std::string get_name(const pool_entry_lookupt &pool_entry) const
221221
{
222222
const pool_entryt &name_entry = pool_entry(name_index);
223223
return read_utf8_constant(name_entry);
@@ -232,21 +232,21 @@ class class_infot : public structured_pool_entryt
232232
class name_and_type_infot : public structured_pool_entryt
233233
{
234234
public:
235-
explicit name_and_type_infot(pool_entryt entry)
235+
explicit name_and_type_infot(const pool_entryt &entry)
236236
: structured_pool_entryt(entry)
237237
{
238238
PRECONDITION(entry.tag == CONSTANT_NameAndType);
239239
name_index = entry.ref1;
240240
descriptor_index = entry.ref2;
241241
}
242242

243-
std::string get_name(pool_entry_lookupt pool_entry) const
243+
std::string get_name(const pool_entry_lookupt &pool_entry) const
244244
{
245245
const pool_entryt &name_entry = pool_entry(name_index);
246246
return read_utf8_constant(name_entry);
247247
}
248248

249-
std::string get_descriptor(pool_entry_lookupt pool_entry) const
249+
std::string get_descriptor(const pool_entry_lookupt &pool_entry) const
250250
{
251251
const pool_entryt &descriptor_entry = pool_entry(descriptor_index);
252252
return read_utf8_constant(descriptor_entry);
@@ -260,7 +260,8 @@ class name_and_type_infot : public structured_pool_entryt
260260
class base_ref_infot : public structured_pool_entryt
261261
{
262262
public:
263-
explicit base_ref_infot(pool_entryt entry) : structured_pool_entryt(entry)
263+
explicit base_ref_infot(const pool_entryt &entry)
264+
: structured_pool_entryt(entry)
264265
{
265266
PRECONDITION(
266267
entry.tag == CONSTANT_Fieldref || entry.tag == CONSTANT_Methodref ||
@@ -278,7 +279,8 @@ class base_ref_infot : public structured_pool_entryt
278279
return name_and_type_index;
279280
}
280281

281-
name_and_type_infot get_name_and_type(pool_entry_lookupt pool_entry) const
282+
name_and_type_infot
283+
get_name_and_type(const pool_entry_lookupt &pool_entry) const
282284
{
283285
const pool_entryt &name_and_type_entry = pool_entry(name_and_type_index);
284286

@@ -290,7 +292,7 @@ class base_ref_infot : public structured_pool_entryt
290292
return name_and_type_infot{name_and_type_entry};
291293
}
292294

293-
class_infot get_class(pool_entry_lookupt pool_entry) const
295+
class_infot get_class(const pool_entry_lookupt &pool_entry) const
294296
{
295297
const pool_entryt &class_entry = pool_entry(class_index);
296298

@@ -321,7 +323,7 @@ class method_handle_infot : public structured_pool_entryt
321323
REF_invokeInterface = 9
322324
};
323325

324-
explicit method_handle_infot(pool_entryt entry)
326+
explicit method_handle_infot(const pool_entryt &entry)
325327
: structured_pool_entryt(entry)
326328
{
327329
PRECONDITION(entry.tag == CONSTANT_MethodHandle);
@@ -330,7 +332,7 @@ class method_handle_infot : public structured_pool_entryt
330332
reference_index = entry.ref2;
331333
}
332334

333-
base_ref_infot get_reference(pool_entry_lookupt pool_entry) const
335+
base_ref_infot get_reference(const pool_entry_lookupt &pool_entry) const
334336
{
335337
const base_ref_infot ref_entry{pool_entry(reference_index)};
336338

@@ -403,20 +405,20 @@ bool java_bytecode_parsert::parse()
403405
return false;
404406
}
405407

406-
#define ACC_PUBLIC 0x0001
407-
#define ACC_PRIVATE 0x0002
408-
#define ACC_PROTECTED 0x0004
409-
#define ACC_STATIC 0x0008
410-
#define ACC_FINAL 0x0010
411-
#define ACC_SYNCHRONIZED 0x0020
412-
#define ACC_BRIDGE 0x0040
413-
#define ACC_NATIVE 0x0100
414-
#define ACC_INTERFACE 0x0200
415-
#define ACC_ABSTRACT 0x0400
416-
#define ACC_STRICT 0x0800
417-
#define ACC_SYNTHETIC 0x1000
418-
#define ACC_ANNOTATION 0x2000
419-
#define ACC_ENUM 0x4000
408+
#define ACC_PUBLIC 0x0001u
409+
#define ACC_PRIVATE 0x0002u
410+
#define ACC_PROTECTED 0x0004u
411+
#define ACC_STATIC 0x0008u
412+
#define ACC_FINAL 0x0010u
413+
#define ACC_SYNCHRONIZED 0x0020u
414+
#define ACC_BRIDGE 0x0040u
415+
#define ACC_NATIVE 0x0100u
416+
#define ACC_INTERFACE 0x0200u
417+
#define ACC_ABSTRACT 0x0400u
418+
#define ACC_STRICT 0x0800u
419+
#define ACC_SYNTHETIC 0x1000u
420+
#define ACC_ANNOTATION 0x2000u
421+
#define ACC_ENUM 0x4000u
420422

421423
#define UNUSED_u2(x) \
422424
{ \
@@ -831,10 +833,6 @@ void java_bytecode_parsert::rconstant_pool()
831833
entry.expr.type() = type;
832834
}
833835
break;
834-
835-
default:
836-
{
837-
};
838836
}
839837
});
840838
}
@@ -918,7 +916,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
918916
bytecode_info[bytecode].mnemonic);
919917
}
920918

921-
instructions.push_back(instructiont());
919+
instructions.emplace_back();
922920
instructiont &instruction=instructions.back();
923921
instruction.bytecode = bytecode;
924922
instruction.address=start_of_instruction;
@@ -1033,7 +1031,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
10331031
u4 base_offset=address;
10341032

10351033
// first a pad to 32-bit align
1036-
while(((address + 1) & 3) != 0)
1034+
while(((address + 1u) & 3u) != 0)
10371035
{
10381036
read<u1>();
10391037
address++;
@@ -1071,7 +1069,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
10711069
size_t base_offset=address;
10721070

10731071
// first a pad to 32-bit align
1074-
while(((address + 1) & 3) != 0)
1072+
while(((address + 1u) & 3u) != 0)
10751073
{
10761074
read<u1>();
10771075
address++;
@@ -1400,7 +1398,7 @@ void java_bytecode_parsert::rcode_attribute(methodt &method)
14001398
}
14011399
else if(252<=frame_type && frame_type<=254)
14021400
{
1403-
size_t new_locals=(size_t) (frame_type-251);
1401+
size_t new_locals = frame_type - 251;
14041402
method.stack_map_table[i].type=methodt::stack_map_table_entryt::APPEND;
14051403
method.stack_map_table[i].locals.resize(new_locals);
14061404
method.stack_map_table[i].stack.resize(0);
@@ -1699,8 +1697,8 @@ void java_bytecode_parsert::rclass_attribute(classt &parsed_class)
16991697
const u2 sourcefile_index = read<u2>();
17001698
irep_idt sourcefile_name;
17011699

1702-
std::string fqn(id2string(parsed_class.name));
1703-
size_t last_index=fqn.find_last_of(".");
1700+
const std::string &fqn(id2string(parsed_class.name));
1701+
size_t last_index = fqn.find_last_of('.');
17041702
if(last_index==std::string::npos)
17051703
sourcefile_name=pool_entry(sourcefile_index).s;
17061704
else
@@ -1764,20 +1762,20 @@ void java_bytecode_parsert::rmethods(classt &parsed_class)
17641762
rmethod(parsed_class);
17651763
}
17661764

1767-
#define ACC_PUBLIC 0x0001
1768-
#define ACC_PRIVATE 0x0002
1769-
#define ACC_PROTECTED 0x0004
1770-
#define ACC_STATIC 0x0008
1771-
#define ACC_FINAL 0x0010
1772-
#define ACC_VARARGS 0x0080
1773-
#define ACC_SUPER 0x0020
1774-
#define ACC_VOLATILE 0x0040
1775-
#define ACC_TRANSIENT 0x0080
1776-
#define ACC_INTERFACE 0x0200
1777-
#define ACC_ABSTRACT 0x0400
1778-
#define ACC_SYNTHETIC 0x1000
1779-
#define ACC_ANNOTATION 0x2000
1780-
#define ACC_ENUM 0x4000
1765+
#define ACC_PUBLIC 0x0001u
1766+
#define ACC_PRIVATE 0x0002u
1767+
#define ACC_PROTECTED 0x0004u
1768+
#define ACC_STATIC 0x0008u
1769+
#define ACC_FINAL 0x0010u
1770+
#define ACC_VARARGS 0x0080u
1771+
#define ACC_SUPER 0x0020u
1772+
#define ACC_VOLATILE 0x0040u
1773+
#define ACC_TRANSIENT 0x0080u
1774+
#define ACC_INTERFACE 0x0200u
1775+
#define ACC_ABSTRACT 0x0400u
1776+
#define ACC_SYNTHETIC 0x1000u
1777+
#define ACC_ANNOTATION 0x2000u
1778+
#define ACC_ENUM 0x4000u
17811779

17821780
void java_bytecode_parsert::rmethod(classt &parsed_class)
17831781
{

0 commit comments

Comments
 (0)