Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jcupitt/libdicom
Browse files Browse the repository at this point in the history
  • Loading branch information
jcupitt committed Oct 31, 2023
2 parents 9cbd1a6 + 3b55252 commit 585bf32
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 78 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
cc: clang
- os: windows-latest
cc: clang
- os: windows-latest
cc: cl
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -58,13 +60,21 @@ jobs:
sudo=sudo
;;
windows*)
# Ignore unused parameter warnings from check.h
export CFLAGS=-Wno-unused-parameter
# https://github.com/mesonbuild/meson/issues/10022
export CC_LD=lld-link
case "${{ matrix.cc }}" in
cl)
# ignore CK_DIAGNOSTIC_POP warnings in check
setup_args="--vsenv -Dcheck:werror=false"
;;
clang)
# Ignore unused parameter warnings from check.h
export CFLAGS=-Wno-unused-parameter
# https://github.com/mesonbuild/meson/issues/10022
export CC_LD=lld-link
;;
esac
;;
esac
meson setup builddir --werror
meson setup builddir --werror $setup_args
meson compile -C builddir
$sudo meson install -C builddir
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## master

## 1.0.2, 5/10/23

- fix a crash and some error pileups [bgilbert]
- fix some retun values [bgilbert]

Check failure on line 6 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / Check for spelling errors

retun ==> return

## 1.0.1, 3/10/23

- fix MSVC compiler warnings [jcupitt]
- only use `__attribute__((constructor))` if supported [bgilbert]

## 1.0.0, 2/10/23

- first release!

7 changes: 0 additions & 7 deletions include/dicom/dicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
#define DCM_EXTERN __attribute__((visibility("default"))) extern
#endif

#ifdef HAS_CONSTRUCTOR
#define DCM_CONSTRUCTOR __attribute__ ((constructor))
#else
#define DCM_CONSTRUCTOR __attribute__ ((constructor))
#endif

/**
* Maximum number of characters in values with Value Representation AE.
*/
Expand Down Expand Up @@ -132,7 +126,6 @@ typedef struct _DcmSequence DcmSequence;
* This function can be called many times.
*/
DCM_EXTERN
DCM_CONSTRUCTOR
void dcm_init(void);

/* Our copy of getopt, since non-glibc platforms are missing this.
Expand Down
10 changes: 2 additions & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(
],
license : 'MIT',
meson_version : '>=0.50',
version : '1.0.0'
version : '1.0.2'
)
if not meson.is_subproject()
meson.add_dist_script(
Expand Down Expand Up @@ -106,13 +106,7 @@ if cc.has_header('unistd.h')
cfg.set('HAVE_UNISTD_H', '1')
endif
# we use a constructor attr for dcm_init()
code = '''#include<stdio.h>
__attribute__ ((constructor)) void func() { printf("constructor\n"); }
'''
cfg.set(
'HAS_CONSTRUCTOR',
cc.compiles(code, name : 'has constructor attribute')
)
cfg.set('HAS_CONSTRUCTOR', cc.has_function_attribute('constructor'))

configure_file(
output : 'config.h',
Expand Down
24 changes: 12 additions & 12 deletions src/dicom-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ bool dcm_element_set_value_string_multi(DcmError **error,

element->vm = vm;

size_t length = 0;
uint32_t length = 0;
for (uint32_t i = 0; i < vm; i++) {
length += strlen(values[i]);
length += (uint32_t) strlen(values[i]);
}
if (vm > 1) {
// add the separator characters
Expand Down Expand Up @@ -576,7 +576,7 @@ bool dcm_element_set_value_string(DcmError **error,
}

element->vm = 1;
element_set_length(element, strlen(value));
element_set_length(element, (uint32_t) strlen(value));

if (!dcm_element_validate(error, element)) {
return false;
Expand All @@ -598,7 +598,7 @@ static int64_t value_to_int64(DcmVR vr, int *value)
{
uint64_t result = 0;

#define PEEK(TYPE) result = *((TYPE *) value)
#define PEEK(TYPE) result = (uint64_t) *((TYPE *) value)
DCM_SWITCH_NUMERIC(vr, PEEK);
#undef PEEK

Expand All @@ -610,7 +610,7 @@ static int64_t value_to_int64(DcmVR vr, int *value)
static void int64_to_value(DcmVR vr, int *result, int64_t value)
{
*result = 0;
#define POKE(TYPE) *((TYPE *) result) = value;
#define POKE(TYPE) *((TYPE *) result) = (TYPE) value;
DCM_SWITCH_NUMERIC(vr, POKE);
#undef POKE
}
Expand Down Expand Up @@ -697,7 +697,7 @@ bool dcm_element_set_value_integer(DcmError **error,
int *element_value = (int *) &element->value.single.sl;
int64_to_value(element->vr, element_value, value);
element->vm = 1;
element_set_length(element, dcm_dict_vr_size(element->vr));
element_set_length(element, (uint32_t) dcm_dict_vr_size(element->vr));

if (!dcm_element_validate(error, element)) {
return false;
Expand Down Expand Up @@ -741,7 +741,7 @@ bool dcm_element_set_value_numeric_multi(DcmError **error,
}

element->vm = vm;
element_set_length(element, size_in_bytes);
element_set_length(element, (uint32_t) size_in_bytes);

if (!dcm_element_validate(error, element)) {
return false;
Expand All @@ -762,7 +762,7 @@ static double value_to_double(DcmVR vr, double *value)
{
double result = 0.0;

#define PEEK(TYPE) result = *((TYPE *) value)
#define PEEK(TYPE) result = (double) *((TYPE *) value)
DCM_SWITCH_NUMERIC(vr, PEEK);
#undef PEEK

Expand All @@ -774,7 +774,7 @@ static double value_to_double(DcmVR vr, double *value)
static void double_to_value(DcmVR vr, double *result, double value)
{
*result = 0.0;
#define POKE(TYPE) *((TYPE *) result) = value;
#define POKE(TYPE) *((TYPE *) result) = (TYPE) value;
DCM_SWITCH_NUMERIC(vr, POKE);
#undef POKE
}
Expand Down Expand Up @@ -834,7 +834,7 @@ bool dcm_element_set_value_decimal(DcmError **error,
double *element_value = (double *) &element->value.single.fd;
double_to_value(element->vr, element_value, value);
element->vm = 1;
element_set_length(element, dcm_dict_vr_size(element->vr));
element_set_length(element, (uint32_t) dcm_dict_vr_size(element->vr));

if (!dcm_element_validate(error, element)) {
return false;
Expand Down Expand Up @@ -948,7 +948,7 @@ bool dcm_element_set_value(DcmError **error,
if (!dcm_element_set_value_numeric_multi(error,
element,
(int *) value,
length / size,
length / (uint32_t) size,
steal)) {
return false;
}
Expand Down Expand Up @@ -1284,7 +1284,7 @@ char *dcm_element_value_to_string(const DcmElement *element)
(void) dcm_element_get_value_integer(NULL, element, 0, &grp);
(void) dcm_element_get_value_integer(NULL, element, 1, &ele);

uint32_t tag = grp << 16 | ele;
uint32_t tag = (uint32_t) grp << 16 | (uint32_t) ele;

const char *keyword = dcm_dict_keyword_from_tag(tag);

Expand Down
3 changes: 3 additions & 0 deletions src/dicom-dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -5083,6 +5083,9 @@ static struct _DcmAttribute_hash_entry *attribute_from_tag_dict = NULL;
static struct _DcmAttribute_hash_entry *attribute_from_keyword_dict = NULL;


#ifdef HAS_CONSTRUCTOR
__attribute__ ((constructor))
#endif
void dcm_init(void)
{
if (!vrtable_from_str_dict) {
Expand Down
39 changes: 21 additions & 18 deletions src/dicom-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ static bool get_frame_size(DcmError **error,
return false;
}

*frame_width = width;
*frame_height = height;
*frame_width = (uint32_t) width;
*frame_height = (uint32_t) height;

return true;
}
Expand Down Expand Up @@ -350,8 +350,8 @@ static bool get_tiles(DcmError **error,
height = frame_width;
(void) get_tag_int(NULL, metadata, "TotalPixelMatrixRows", &height);

*tiles_across = width / frame_width + !!(width % frame_width);
*tiles_down = height / frame_height + !!(height % frame_height);
*tiles_across = (uint32_t) width / frame_width + !!(width % frame_width);
*tiles_down = (uint32_t) height / frame_height + !!(height % frame_height);

return true;
}
Expand Down Expand Up @@ -536,7 +536,7 @@ static DcmDataSet *dcm_filehandle_read_file_meta(DcmError **error,
false,
&parse,
filehandle)) {
return false;
return NULL;
}

/* Sanity check. We should have parsed a single dataset into the sequence
Expand All @@ -555,8 +555,8 @@ static DcmDataSet *dcm_filehandle_read_file_meta(DcmError **error,
}

DcmDataSet *file_meta = dcm_sequence_get(error, sequence, 0);
if (file_meta == NULL ) {
return false;
if (file_meta == NULL) {
return NULL;
}

// steal file_meta to stop it being destroyed
Expand Down Expand Up @@ -664,49 +664,49 @@ static bool set_pixel_description(DcmError **error,
!dcm_element_get_value_integer(error, element, 0, &value)) {
return false;
}
desc->rows = value;
desc->rows = (uint16_t) value;

element = dcm_dataset_get(error, metadata, 0x00280011);
if (element == NULL ||
!dcm_element_get_value_integer(error, element, 0, &value)) {
return false;
}
desc->columns = value;
desc->columns = (uint16_t) value;

element = dcm_dataset_get(error, metadata, 0x00280002);
if (element == NULL ||
!dcm_element_get_value_integer(error, element, 0, &value)) {
return false;
}
desc->samples_per_pixel = value;
desc->samples_per_pixel = (uint16_t) value;

element = dcm_dataset_get(error, metadata, 0x00280100);
if (element == NULL ||
!dcm_element_get_value_integer(error, element, 0, &value)) {
return false;
}
desc->bits_allocated = value;
desc->bits_allocated = (uint16_t) value;

element = dcm_dataset_get(error, metadata, 0x00280101);
if (element == NULL ||
!dcm_element_get_value_integer(error, element, 0, &value)) {
return false;
}
desc->bits_stored = value;
desc->bits_stored = (uint16_t) value;

element = dcm_dataset_get(error, metadata, 0x00280103);
if (element == NULL ||
!dcm_element_get_value_integer(error, element, 0, &value)) {
return false;
}
desc->pixel_representation = value;
desc->pixel_representation = (uint16_t) value;

element = dcm_dataset_get(error, metadata, 0x00280006);
if (element == NULL ||
!dcm_element_get_value_integer(error, element, 0, &value)) {
return false;
}
desc->planar_configuration = value;
desc->planar_configuration = (uint16_t) value;

element = dcm_dataset_get(error, metadata, 0x00280004);
if (element == NULL ||
Expand Down Expand Up @@ -765,7 +765,7 @@ DcmDataSet *dcm_filehandle_read_metadata(DcmError **error,
filehandle->implicit,
&parse,
filehandle)) {
return false;
return NULL;
}

/* Sanity check. We should have parsed a single dataset into the sequence
Expand All @@ -784,8 +784,8 @@ DcmDataSet *dcm_filehandle_read_metadata(DcmError **error,
}

DcmDataSet *meta = dcm_sequence_get(error, sequence, 0);
if (meta == NULL ) {
return false;
if (meta == NULL) {
return NULL;
}

// steal meta to stop it being destroyed
Expand Down Expand Up @@ -821,6 +821,9 @@ const DcmDataSet *dcm_filehandle_get_metadata_subset(DcmError **error,
DcmDataSet *meta = dcm_filehandle_read_metadata(error,
filehandle,
stop_tags);
if (meta == NULL) {
return NULL;
}

// record the position of the tag that stopped the read
if (!dcm_offset(error, filehandle, &filehandle->after_read_metadata)) {
Expand All @@ -838,7 +841,7 @@ const DcmDataSet *dcm_filehandle_get_metadata_subset(DcmError **error,
&filehandle->tiles_across, &filehandle->tiles_down) ||
!set_pixel_description(error, meta, &filehandle->desc)) {
dcm_dataset_destroy(meta);
return false;
return NULL;
}
filehandle->num_tiles = filehandle->tiles_across *
filehandle->tiles_down;
Expand Down
Loading

0 comments on commit 585bf32

Please sign in to comment.