Skip to content

Commit 8864531

Browse files
remove a few signed/unsigned warnings
Where appropriate, test if index is actually positive or at least 1.
1 parent 6cc97a3 commit 8864531

File tree

9 files changed

+25
-12
lines changed

9 files changed

+25
-12
lines changed

src/buildblock/TimeFrameDefinitions.cxx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ START_NAMESPACE_STIR
4949
double
5050
TimeFrameDefinitions::get_start_time(unsigned int frame_num) const
5151
{
52+
if (frame_num < 1)
53+
throw std::runtime_error("TimeFrameDefinitions::get_start_time called for frame " + std::to_string(frame_num)
54+
+ ", but it should be at least 1.");
5255
if (frame_num > frame_times.size())
5356
throw std::runtime_error("TimeFrameDefinitions: asked for frame " + std::to_string(frame_num) + ", but only "
5457
+ std::to_string(frame_times.size()) + " frames present.");
@@ -58,6 +61,9 @@ TimeFrameDefinitions::get_start_time(unsigned int frame_num) const
5861
double
5962
TimeFrameDefinitions::get_end_time(unsigned int frame_num) const
6063
{
64+
if (frame_num < 1)
65+
throw std::runtime_error("TimeFrameDefinitions::get_end_time called for frame " + std::to_string(frame_num)
66+
+ ", but it should be at least 1.");
6167
if (frame_num > frame_times.size())
6268
throw std::runtime_error("TimeFrameDefinitions: asked for frame " + std::to_string(frame_num) + ", but only "
6369
+ std::to_string(frame_times.size()) + " frames present.");
@@ -253,8 +259,11 @@ TimeFrameDefinitions::TimeFrameDefinitions(const TimeFrameDefinitions& org_frame
253259
}
254260

255261
void
256-
TimeFrameDefinitions::set_time_frame(const int frame_num, const double start, const double end)
262+
TimeFrameDefinitions::set_time_frame(const unsigned int frame_num, const double start, const double end)
257263
{
264+
if (frame_num < 1)
265+
throw std::runtime_error("TimeFrameDefinitions::set_time_frame called for frame " + std::to_string(frame_num)
266+
+ ", but it should be at least 1.");
258267
if (frame_num > frame_times.size())
259268
throw std::runtime_error("TimeFrameDefinitions::set_time_frame called for frame " + std::to_string(frame_num) + ", but only "
260269
+ std::to_string(frame_times.size()) + " frames present.");
@@ -265,7 +274,7 @@ TimeFrameDefinitions::set_time_frame(const int frame_num, const double start, co
265274
bool
266275
TimeFrameDefinitions::operator==(const TimeFrameDefinitions& t) const
267276
{
268-
for (int frame = 0; frame < frame_times.size(); frame++)
277+
for (int frame = 0; static_cast<unsigned>(frame) < frame_times.size(); frame++)
269278
{
270279

271280
const bool is_identical = (std::abs(frame_times.at(frame).first - t.frame_times.at(frame).first) <= 10e-5)

src/data_buildblock/SinglesRatesFromGEHDF5.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SinglesRatesFromGEHDF5::read_from_file(const std::string& rdf_filename)
6262
// GE uses unsigned int, while SinglesRateForTimeSlices uses int, so we need a copy
6363
Array<2, unsigned int> GE_singles(IndexRange2D(0, _num_time_slices - 1, 0, total_singles_units - 1));
6464

65-
while (slice < _num_time_slices)
65+
while (slice < static_cast<unsigned>(_num_time_slices))
6666
{
6767
m_input_sptr->read_singles(GE_singles[slice], slice + 1);
6868
++slice;
@@ -73,7 +73,7 @@ SinglesRatesFromGEHDF5::read_from_file(const std::string& rdf_filename)
7373
std::copy(GE_singles.begin_all(), GE_singles.end_all(), _singles.begin_all());
7474

7575
// PW Modify this bit of code too.
76-
if (slice != _num_time_slices)
76+
if (slice != static_cast<unsigned>(_num_time_slices))
7777
{
7878
error("\nSinglesRatesFromGEHDF5: Couldn't read all records in the file. Read %d of %d. Exiting\n", slice, _num_time_slices);
7979
// TODO resize singles to return array with new sizes
@@ -83,7 +83,7 @@ SinglesRatesFromGEHDF5::read_from_file(const std::string& rdf_filename)
8383
{
8484
// GE RDF9 listmode stores singles every second
8585
_singles_time_interval = 1.0;
86-
for (unsigned int slice = 0; slice < _num_time_slices; ++slice)
86+
for (unsigned int slice = 0; slice < static_cast<unsigned>(_num_time_slices); ++slice)
8787
_times[slice] = slice + _singles_time_interval; // note that this has to store the "end-time" of the slice
8888

8989
assert(_times.size() != 0);

src/include/stir/TimeFrameDefinitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class TimeFrameDefinitions
9898
void set_num_time_frames(int num_time_frames) { frame_times.resize(num_time_frames); }
9999

100100
//! Set time frame
101-
void set_time_frame(const int frame_num, const double start, const double end);
101+
void set_time_frame(const unsigned int frame_num, const double start, const double end);
102102

103103
bool operator==(const TimeFrameDefinitions& t) const;
104104

src/include/stir/recon_buildblock/DataSymmetriesForBins_PET_CartesianGrid.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ DataSymmetriesForBins_PET_CartesianGrid::num_related_view_segment_numbers(const
687687
int
688688
DataSymmetriesForBins_PET_CartesianGrid::num_related_bins(const Bin& b) const
689689
{
690-
int num;
690+
int num = 0;
691691
// cylindrical implementaion
692692
if (proj_data_info_ptr->get_scanner_ptr()->get_scanner_geometry() == "Cylindrical")
693693
{

src/iterative/KOSMAPOSL/KOSMAPOSLReconstruction.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ void
418418
KOSMAPOSLReconstruction<TargetT>::set_anatomical_prior_sptr(shared_ptr<TargetT> arg, int index)
419419
{
420420
this->_already_set_up = false;
421-
if (index < this->anatomical_prior_sptrs.size())
421+
if (index < 0)
422+
error("KOSMAPOSLReconstruction::set_anatomical_prior_sptr called with negative index");
423+
if (static_cast<unsigned>(index) < this->anatomical_prior_sptrs.size())
422424
this->anatomical_prior_sptrs.at(index) = arg;
423425
else
424426
this->anatomical_prior_sptrs.push_back(arg);
@@ -438,6 +440,8 @@ void
438440
KOSMAPOSLReconstruction<TargetT>::set_anatomical_image_filename(const std::string& arg, const int index)
439441
{
440442
this->_already_set_up = false;
443+
if (index < 0)
444+
error("KOSMAPOSLReconstruction::set_anatomical_image_filename called with negative index");
441445
if (static_cast<unsigned>(index) < this->anatomical_image_filenames.size())
442446
this->anatomical_image_filenames.at(index) = arg;
443447
else

src/test/IO/test_IO_DynamicDiscretisedDensity.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ IOTests_DynamicDiscretisedDensity::check_result()
123123
std::cerr << "\tChecking the exam info...\n";
124124
check_exam_info(_image_to_write_sptr->get_exam_info(), _image_to_read_sptr->get_exam_info());
125125

126-
for (int i = 1; i <= _image_to_read_sptr->get_densities().size(); ++i)
126+
for (int i = 1; static_cast<unsigned>(i) <= _image_to_read_sptr->get_densities().size(); ++i)
127127
{
128128

129129
std::cerr << "\t\tChecking dynamic image " << i << "...\n";

src/test/IO/test_IO_ParametricDiscretisedDensity.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ IOTests_ParametricDiscretisedDensity::check_result()
132132
std::cerr << "\tChecking the exam info...\n";
133133
check_exam_info(_image_to_write_sptr->get_exam_info(), _image_to_read_sptr->get_exam_info());
134134

135-
for (int i = 1; i <= _image_to_read_sptr->get_num_params(); ++i)
135+
for (int i = 1; static_cast<unsigned>(i) <= _image_to_read_sptr->get_num_params(); ++i)
136136
{
137137

138138
std::cerr << "\t\tChecking kinetic parameter " << i << "...\n";

src/utilities/GE/print_GE_singles_values.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ main(int argc, char** argv)
6969
Array<3, float> singles_arr(IndexRange3D(
7070
time_def.get_num_time_frames(), scanner.get_num_axial_singles_units(), scanner.get_num_transaxial_singles_units()));
7171

72-
for (int time_frame_num = 1; time_frame_num <= time_def.get_num_time_frames(); ++time_frame_num)
72+
for (int time_frame_num = 1; static_cast<unsigned>(time_frame_num) <= time_def.get_num_time_frames(); ++time_frame_num)
7373
{
7474
for (int ax = 0; ax < scanner.get_num_axial_singles_units(); ++ax)
7575
{

src/utilities/separate_true_from_random_scatter_for_necr.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ main(int argc, char* argv[])
262262
float random_and_scatter = random_and_scatter_inside_14mm + random_and_scatter_outside_14mm;
263263

264264
float total_event_number = 0;
265-
for (int idx = 0; idx < squeezed_sino_all.size(); ++idx)
265+
for (int idx = 0; static_cast<unsigned>(idx) < squeezed_sino_all.size(); ++idx)
266266
{
267267
total_event_number += squeezed_sino_all[idx];
268268
}

0 commit comments

Comments
 (0)