Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MSVC warnings, version bump #69

Merged
merged 9 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## master

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

## 1.0.0, 2/9/23

- first release!

2 changes: 1 addition & 1 deletion 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.1'
)
if not meson.is_subproject()
meson.add_dist_script(
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
22 changes: 11 additions & 11 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 @@ -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
23 changes: 12 additions & 11 deletions src/dicom-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ typedef struct _DcmIOFile {
int fd;
char *filename;
char input_buffer[BUFFER_SIZE];
int bytes_in_buffer;
int read_point;
int64_t bytes_in_buffer;
int64_t read_point;
} DcmIOFile;


Expand Down Expand Up @@ -120,7 +120,8 @@ static int64_t read_file(DcmError **error, DcmIOFile *file,
int64_t bytes_read;

#ifdef _WIN32
bytes_read = _read(file->fd, buffer, length);
// we'll never read a huge chunk (hopefully)
bytes_read = _read(file->fd, buffer, (uint32_t) length);
#else
do {
bytes_read = read(file->fd, buffer, length);
Expand Down Expand Up @@ -179,8 +180,8 @@ static int64_t dcm_io_read_file(DcmError **error, DcmIO *io,

/* Read what we can from the buffer.
*/
int bytes_available = file->bytes_in_buffer - file->read_point;
int bytes_to_copy = MIN(bytes_available, length);
int64_t bytes_available = file->bytes_in_buffer - file->read_point;
int64_t bytes_to_copy = MIN(bytes_available, length);

memcpy(buffer,
file->input_buffer + file->read_point,
Expand Down Expand Up @@ -309,8 +310,8 @@ static int64_t dcm_io_read_memory(DcmError **error, DcmIO *io,

USED(error);

int bytes_available = memory->length - memory->read_point;
int bytes_to_copy = MIN(bytes_available, length);
int64_t bytes_available = memory->length - memory->read_point;
int64_t bytes_to_copy = MIN(bytes_available, length);
memcpy(buffer,
memory->buffer + memory->read_point,
bytes_to_copy);
Expand Down Expand Up @@ -355,7 +356,7 @@ static int64_t dcm_io_seek_memory(DcmError **error, DcmIO *io,


DcmIO *dcm_io_create_from_memory(DcmError **error,
const char *buffer,
const char *buffer,
int64_t length)
{
static DcmIOMethods methods = {
Expand Down Expand Up @@ -391,9 +392,9 @@ int64_t dcm_io_read(DcmError **error,
}


int64_t dcm_io_seek(DcmError **error,
DcmIO *io,
int64_t offset,
int64_t dcm_io_seek(DcmError **error,
DcmIO *io,
int64_t offset,
int whence)
{
return io->methods->seek(error, io, offset, whence);
Expand Down
27 changes: 14 additions & 13 deletions tests/check_dicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static size_t compute_length_of_string_value_multi(char **values,
}


static char *load_file_to_memory(const char *name, long *length_out)
static char *load_file_to_memory(const char *name, int64_t *length_out)
{
FILE *fp;

Expand All @@ -82,7 +82,7 @@ static char *load_file_to_memory(const char *name, long *length_out)
free(full_path);

fseek(fp, 0, SEEK_END);
long length = ftell(fp);
int64_t length = ftell(fp);
fseek(fp, 0, SEEK_SET);

if (length < 0) {
Expand All @@ -96,12 +96,12 @@ static char *load_file_to_memory(const char *name, long *length_out)
return NULL;
}

long total_read = 0;
int64_t total_read = 0;
while (total_read < length) {
size_t bytes_read = fread(result + total_read,
1,
length - total_read,
fp);
int64_t bytes_read = fread(result + total_read,
1,
length - total_read,
fp);
total_read += bytes_read;
}

Expand Down Expand Up @@ -302,7 +302,8 @@ START_TEST(test_element_CS_multivalue_empty)
uint32_t tag = 0x00080008;
uint32_t vm = 0;

char **values = malloc(vm * sizeof(char *));
// since malloc(0) can be NULL on some platforms
char **values = malloc(1);

DcmElement *element = dcm_element_create(NULL, tag, DCM_VR_CS);
(void) dcm_element_set_value_string_multi(NULL, element, values, vm, true);
Expand Down Expand Up @@ -528,15 +529,15 @@ END_TEST
START_TEST(test_element_US_multivalue_empty)
{
uint32_t tag = 0x00280010;
uint16_t value[] = {};
uint32_t vm = sizeof(value) / sizeof(value[0]);
// msvc hates zero length arrays, so use 1
uint16_t value[] = {0};

DcmElement *element = dcm_element_create(NULL, tag, DCM_VR_US);
(void) dcm_element_set_value_numeric_multi(NULL, element, &value, vm, false);
(void) dcm_element_set_value_numeric_multi(NULL, element, &value, 0, false);

ck_assert_int_eq(dcm_element_get_tag(element), tag);
ck_assert_int_eq(dcm_element_get_vr(element), DCM_VR_US);
ck_assert_int_eq(dcm_element_get_length(element), sizeof(value));
ck_assert_int_eq(dcm_element_get_length(element), 0);
ck_assert_int_eq(dcm_element_is_multivalued(element), false);

dcm_element_print(element, 0);
Expand Down Expand Up @@ -739,7 +740,7 @@ START_TEST(test_file_sm_image_file_meta_memory)
DcmElement *element;
const char *value;

long length;
int64_t length;
char *memory = load_file_to_memory("data/test_files/sm_image.dcm", &length);
ck_assert_ptr_nonnull(memory);

Expand Down