Skip to content
Closed
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
10 changes: 4 additions & 6 deletions src/dicom-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1431,18 +1431,16 @@ bool dcm_filehandle_get_frame_number(DcmError **error,
if (filehandle->layout == DCM_LAYOUT_SPARSE) {
index = filehandle->frame_index[index];
if (index == 0xffffffff) {
dcm_error_set(error, DCM_ERROR_CODE_MISSING_FRAME,
"no frame",
"no frame at position (%u, %u)", column, row);
// we might return this error hundreds of thousands of times;
// avoid allocating each time
dcm_error_set_static(error, &DCM_STATIC_ERROR_MISSING_FRAME);
return false;
}
} else {
// subtract the start of this file, for catenation support
index -= filehandle->frame_offset;
if (index < 0 || index >= (int64_t) filehandle->num_frames) {
dcm_error_set(error, DCM_ERROR_CODE_MISSING_FRAME,
"no frame",
"no frame at position (%u, %u)", column, row);
dcm_error_set_static(error, &DCM_STATIC_ERROR_MISSING_FRAME);
return false;
}
}
Expand Down
22 changes: 21 additions & 1 deletion src/dicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,19 @@ struct _DcmError {
DcmErrorCode code;
char *summary;
char *message;
bool is_static;
};

const DcmError DCM_STATIC_ERROR_MISSING_FRAME = {
.code = DCM_ERROR_CODE_MISSING_FRAME,
.summary = "no frame",
.message = "no frame at this position",
.is_static = true,
};

static void dcm_error_free(DcmError *error)
{
if (error) {
if (error && !error->is_static) {
free(error->summary);
error->summary = NULL;
free(error->message);
Expand Down Expand Up @@ -252,6 +260,18 @@ void dcm_error_set(DcmError **error, DcmErrorCode code,
}


void dcm_error_set_static(DcmError **error, const DcmError *static_error) {
if (!static_error->is_static) {
dcm_log_critical("DcmError is not static");
} else if (error && *error) {
dcm_log_critical("DcmError set twice");
} else if (error) {
*error = (DcmError *) static_error;
}
/* otherwise don't log; we're in a fast path */
}


void dcm_error_clear(DcmError **error)
{
if (error) {
Expand Down
3 changes: 3 additions & 0 deletions src/pdicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ char *dcm_printf_append(char *str, const char *format, ...);

void dcm_free_string_array(char **strings, int n);

extern const DcmError DCM_STATIC_ERROR_MISSING_FRAME;
void dcm_error_set_static(DcmError **error, const DcmError *static_error);

size_t dcm_dict_vr_size(DcmVR vr);
uint32_t dcm_dict_vr_capacity(DcmVR vr);
int dcm_dict_vr_header_length(DcmVR vr);
Expand Down
Loading