Skip to content

Commit 8e7f129

Browse files
Correct types from unsigned to std::size_t
The block numbers in cover_basic_blockst are obtained from `block_info.size() - 1`, they should have type std::size_t rather than unsigned. Also mark const a couple of arguments that are constant.
1 parent 0fc9c5e commit 8e7f129

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/goto-instrument/cover_basic_blocks.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Author: Peter Schrammel
1515
#include <util/message.h>
1616
#include <util/string2int.h>
1717

18-
optionalt<unsigned> cover_basic_blockst::continuation_of_block(
18+
optionalt<std::size_t> cover_basic_blockst::continuation_of_block(
1919
const goto_programt::const_targett &instruction,
2020
cover_basic_blockst::block_mapt &block_map)
2121
{
@@ -32,7 +32,7 @@ optionalt<unsigned> cover_basic_blockst::continuation_of_block(
3232
cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
3333
{
3434
bool next_is_target = true;
35-
unsigned current_block = 0;
35+
std::size_t current_block = 0;
3636

3737
forall_goto_program_instructions(it, _goto_program)
3838
{
@@ -87,22 +87,22 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
8787
update_covered_lines(block_info);
8888
}
8989

90-
unsigned cover_basic_blockst::block_of(goto_programt::const_targett t) const
90+
std::size_t cover_basic_blockst::block_of(goto_programt::const_targett t) const
9191
{
9292
const auto it = block_map.find(t);
9393
INVARIANT(it != block_map.end(), "instruction must be part of a block");
9494
return it->second;
9595
}
9696

9797
optionalt<goto_programt::const_targett>
98-
cover_basic_blockst::instruction_of(unsigned block_nr) const
98+
cover_basic_blockst::instruction_of(const std::size_t block_nr) const
9999
{
100100
INVARIANT(block_nr < block_infos.size(), "block number out of range");
101101
return block_infos.at(block_nr).representative_inst;
102102
}
103103

104104
const source_locationt &
105-
cover_basic_blockst::source_location_of(unsigned block_nr) const
105+
cover_basic_blockst::source_location_of(const std::size_t block_nr) const
106106
{
107107
INVARIANT(block_nr < block_infos.size(), "block number out of range");
108108
return block_infos.at(block_nr).source_location;
@@ -113,12 +113,12 @@ void cover_basic_blockst::select_unique_java_bytecode_indices(
113113
message_handlert &message_handler)
114114
{
115115
messaget msg(message_handler);
116-
std::set<unsigned> blocks_seen;
116+
std::set<std::size_t> blocks_seen;
117117
std::set<irep_idt> bytecode_indices_seen;
118118

119119
forall_goto_program_instructions(it, goto_program)
120120
{
121-
const unsigned block_nr = block_of(it);
121+
const std::size_t block_nr = block_of(it);
122122
if(blocks_seen.find(block_nr) != blocks_seen.end())
123123
continue;
124124

@@ -181,10 +181,10 @@ void cover_basic_blockst::report_block_anomalies(
181181
message_handlert &message_handler)
182182
{
183183
messaget msg(message_handler);
184-
std::set<unsigned> blocks_seen;
184+
std::set<std::size_t> blocks_seen;
185185
forall_goto_program_instructions(it, goto_program)
186186
{
187-
const unsigned block_nr = block_of(it);
187+
const std::size_t block_nr = block_of(it);
188188
const block_infot &block_info = block_infos.at(block_nr);
189189

190190
if(

src/goto-instrument/cover_basic_blocks.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ class cover_basic_blockst final
2626
/// \param t a goto instruction
2727
/// \return the block number of the block
2828
/// the given goto instruction is part of
29-
unsigned block_of(goto_programt::const_targett t) const;
29+
std::size_t block_of(goto_programt::const_targett t) const;
3030

3131
/// \param block_nr a block number
3232
/// \return the instruction selected for
3333
/// instrumentation representative of the given block
3434
optionalt<goto_programt::const_targett>
35-
instruction_of(unsigned block_nr) const;
35+
instruction_of(std::size_t block_nr) const;
3636

3737
/// \param block_nr a block number
3838
/// \return the source location selected for
3939
/// instrumentation representative of the given block
40-
const source_locationt &source_location_of(unsigned block_nr) const;
40+
const source_locationt &source_location_of(std::size_t block_nr) const;
4141

4242
/// Select an instruction to be instrumented for each basic block such that
4343
/// the java bytecode indices for each basic block is unique
@@ -58,7 +58,7 @@ class cover_basic_blockst final
5858
void output(std::ostream &out) const;
5959

6060
private:
61-
typedef std::map<goto_programt::const_targett, unsigned> block_mapt;
61+
typedef std::map<goto_programt::const_targett, std::size_t> block_mapt;
6262

6363
struct block_infot
6464
{
@@ -71,7 +71,7 @@ class cover_basic_blockst final
7171
source_locationt source_location;
7272

7373
/// the set of lines belonging to this block
74-
std::unordered_set<unsigned> lines;
74+
std::unordered_set<std::size_t> lines;
7575
};
7676

7777
/// map program locations to block numbers
@@ -85,7 +85,7 @@ class cover_basic_blockst final
8585

8686
/// If this block is a continuation of a previous block through unconditional
8787
/// forward gotos, return this blocks number.
88-
static optionalt<unsigned> continuation_of_block(
88+
static optionalt<std::size_t> continuation_of_block(
8989
const goto_programt::const_targett &instruction,
9090
block_mapt &block_map);
9191
};

0 commit comments

Comments
 (0)