Skip to content
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
11 changes: 7 additions & 4 deletions nifti2/nifti2_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -6043,10 +6043,13 @@ nifti_image *nifti_image_read( const char *hname , int read_data )

#ifdef REJECT_COMPLEX
if ((nim->datatype == DT_COMPLEX64) || (nim->datatype == DT_COMPLEX128) || (nim->datatype == DT_COMPLEX256)) {
fprintf(stderr,"Image Exception Unsupported datatype (COMPLEX64): use fslcomplex to manipulate: %s\n", hname);
exit(13);
}
#endif
fprintf(stderr,"Image Exception Unsupported datatype (COMPLEX): use fslcomplex to manipulate: %s\n", hname);
nifti_image_free(nim);
znzclose(fp);
free(hfile);
return NULL;
}
#endif

if( g_opts.debug > 3 ){
fprintf(stderr,"+d nifti_image_read(), have nifti image:\n");
Expand Down
9 changes: 9 additions & 0 deletions niftilib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ if(NIFTI_BUILD_TESTING AND NIFTI_BUILD_APPLICATIONS)
COMMAND $<TARGET_FILE:${NIFTI_PACKAGE_PREFIX}nifti_short_read_test>
)

if(FSLSTYLE_REJECT_COMPLEX)
add_executable(${NIFTI_PACKAGE_PREFIX}nifti_reject_complex_test nifti_reject_complex_test.c)
target_link_libraries(${NIFTI_PACKAGE_PREFIX}nifti_reject_complex_test ${NIFTI_NIFTILIB_NAME})
add_test(
NAME nifti_reject_complex
COMMAND $<TARGET_FILE:${NIFTI_PACKAGE_PREFIX}nifti_reject_complex_test>
)
endif()

add_executable(nifti_second_test_program nifti_tester002.c)
target_link_libraries(nifti_second_test_program ${NIFTI_PACKAGE_PREFIX}niftiio )

Expand Down
11 changes: 7 additions & 4 deletions niftilib/nifti1_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4326,10 +4326,13 @@ nifti_image *nifti_image_read( const char *hname , int read_data )

#ifdef REJECT_COMPLEX
if ((nim->datatype == DT_COMPLEX64) || (nim->datatype == DT_COMPLEX128) || (nim->datatype == DT_COMPLEX256)) {
fprintf(stderr,"Image Exception Unsupported datatype (COMPLEX64): use fslcomplex to manipulate: %s\n", hname);
exit(13);
}
#endif
fprintf(stderr,"Image Exception Unsupported datatype (COMPLEX): use fslcomplex to manipulate: %s\n", hname);
nifti_image_free(nim);
znzclose(fp);
free(hfile);
return NULL;
}
#endif

if( g_opts.debug > 3 ){
fprintf(stderr,"+d nifti_image_read(), have nifti image:\n");
Expand Down
52 changes: 52 additions & 0 deletions niftilib/nifti_reject_complex_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* With REJECT_COMPLEX, nifti_image_read() must report a complex image to
its caller and keep reading non-complex images. */

#include <stdio.h>
#include <stdlib.h>
#include "nifti1_io.h"

static int write_image(const char *fname, int datatype)
{
int dims[8] = { 3, 4, 4, 4, 1, 1, 1, 1 };
nifti_image *nim = nifti_make_new_nim(dims, datatype, 1);
if( nim == NULL ){
fprintf(stderr, "FAILURE: could not create image for %s\n", fname);
return 1;
}
if( nifti_set_filenames(nim, fname, 0, 1) != 0 ){
fprintf(stderr, "FAILURE: could not set filenames for %s\n", fname);
nifti_image_free(nim);
return 1;
}
nifti_image_write(nim);
nifti_image_free(nim);
return 0;
}

int main(void)
{
const char *cplx = "reject_complex_cplx.nii";
const char *real = "reject_complex_real.nii";
nifti_image *nim;

if( write_image(cplx, DT_COMPLEX64) ) return 1;
if( write_image(real, DT_FLOAT32) ) return 1;

nim = nifti_image_read(cplx, 1);
if( nim != NULL ){
fprintf(stderr, "FAILURE: complex image was accepted\n");
nifti_image_free(nim);
return 1;
}

/* the rejection must be specific, not a blanket refusal */
nim = nifti_image_read(real, 1);
if( nim == NULL ){
fprintf(stderr, "FAILURE: non-complex image was rejected\n");
return 1;
}
nifti_image_free(nim);

printf("REJECT_COMPLEX test passed.\n");
return 0;
}
Loading