Skip to content

Commit 030b427

Browse files
authored
fix a compiler warning (#61)
1 parent ead3486 commit 030b427

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/dicom-data.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,24 +1646,32 @@ bool dcm_sequence_append(DcmError **error, DcmSequence *seq, DcmDataSet *item)
16461646
}
16471647

16481648

1649-
static bool sequence_check_index(DcmError **error,
1650-
const DcmSequence *seq, uint32_t index)
1649+
static struct SequenceItem *sequence_get_index(const DcmSequence *seq,
1650+
uint32_t index)
1651+
{
1652+
return (struct SequenceItem*)utarray_eltptr(seq->items, index);
1653+
}
1654+
1655+
1656+
static struct SequenceItem *sequence_check_index(DcmError **error,
1657+
const DcmSequence *seq,
1658+
uint32_t index)
16511659
{
16521660
uint32_t length = utarray_len(seq->items);
16531661
if (index >= length) {
16541662
dcm_error_set(error, DCM_ERROR_CODE_INVALID,
16551663
"Item of Sequence invalid",
16561664
"Index %i exceeds length of sequence %i",
16571665
index, length);
1658-
return false;
1666+
return NULL;
16591667
}
16601668

1661-
struct SequenceItem *seq_item = utarray_eltptr(seq->items, index);
1669+
struct SequenceItem *seq_item = sequence_get_index(seq, index);
16621670
if (seq_item == NULL) {
16631671
dcm_error_set(error, DCM_ERROR_CODE_INVALID,
16641672
"Item of Sequence invalid",
16651673
"Getting item #%i of Sequence failed", index);
1666-
return false;
1674+
return NULL;
16671675
}
16681676
if (seq_item->dataset == NULL) {
16691677
dcm_error_set(error, DCM_ERROR_CODE_INVALID,
@@ -1672,18 +1680,18 @@ static bool sequence_check_index(DcmError **error,
16721680
return NULL;
16731681
}
16741682

1675-
return true;
1683+
return seq_item;
16761684
}
16771685

16781686

16791687
DcmDataSet *dcm_sequence_get(DcmError **error,
16801688
const DcmSequence *seq, uint32_t index)
16811689
{
1682-
if (!sequence_check_index(error, seq, index)) {
1690+
struct SequenceItem *seq_item = sequence_check_index(error, seq, index);
1691+
if (seq_item == NULL) {
16831692
return NULL;
16841693
}
16851694

1686-
struct SequenceItem *seq_item = utarray_eltptr(seq->items, index);
16871695
dcm_dataset_lock(seq_item->dataset);
16881696

16891697
return seq_item->dataset;
@@ -1693,11 +1701,11 @@ DcmDataSet *dcm_sequence_get(DcmError **error,
16931701
DcmDataSet *dcm_sequence_steal(DcmError **error,
16941702
const DcmSequence *seq, uint32_t index)
16951703
{
1696-
if (!sequence_check_index(error, seq, index)) {
1704+
struct SequenceItem *seq_item = sequence_check_index(error, seq, index);
1705+
if (seq_item == NULL) {
16971706
return NULL;
16981707
}
16991708

1700-
struct SequenceItem *seq_item = utarray_eltptr(seq->items, index);
17011709
DcmDataSet *result = seq_item->dataset;
17021710
//dcm_dataset_lock(result);
17031711
seq_item->dataset = NULL;
@@ -1716,7 +1724,7 @@ bool dcm_sequence_foreach(const DcmSequence *seq,
17161724
{
17171725
uint32_t length = utarray_len(seq->items);
17181726
for (uint32_t index = 0; index < length; index++) {
1719-
struct SequenceItem *seq_item = utarray_eltptr(seq->items, index);
1727+
struct SequenceItem *seq_item = sequence_get_index(seq, index);
17201728
DcmDataSet *dataset = seq_item->dataset;
17211729

17221730
dcm_dataset_lock(dataset);
@@ -1733,7 +1741,7 @@ bool dcm_sequence_foreach(const DcmSequence *seq,
17331741
bool dcm_sequence_remove(DcmError **error, DcmSequence *seq, uint32_t index)
17341742
{
17351743
if (!sequence_check_not_locked(error, seq) ||
1736-
!sequence_check_index(error, seq, index)) {
1744+
sequence_check_index(error, seq, index) == NULL) {
17371745
return false;
17381746
}
17391747

0 commit comments

Comments
 (0)