| 1 | /* |
| 2 | * nifti_test2 -- this exercises a particular bug, whereby nifti_copy_nim_info was |
| 3 | * not working correctly, which left the copy of an image pointing to the same |
| 4 | * extension list, which could cause all sorts of grief. |
| 5 | */ |
| 6 | #include <nifti1_io.h> |
| 7 | int main (int argc, const char *argv[]) |
| 8 | { |
| 9 | if (argc > 1) |
| 10 | { |
| 11 | printf("The test program takes no arguments: %s", argv[0]); |
| 12 | return EXIT_FAILURE; |
| 13 | } |
| 14 | |
| 15 | /* |
| 16 | * create a 'dummy' image |
| 17 | */ |
| 18 | nifti_image *i1 = nifti_simple_init_nim(); |
| 19 | nifti_image *i2; |
| 20 | |
| 21 | /* |
| 22 | * add an extension to the dummy |
| 23 | */ |
| 24 | static char ext[] = "THIS IS A TEST"; |
| 25 | nifti_add_extension(i1,ext,sizeof(ext),NIFTI_ECODE_COMMENT); |
| 26 | /* |
| 27 | * make a new nim from the dummy |
| 28 | */ |
| 29 | i2 = nifti_copy_nim_info(i1); |
| 30 | /* |
| 31 | * if the bug isn't fixed in niftilib, the second nifti_image_free |
| 32 | * will fail because both nims point to the same extensions. With gcc |
| 33 | * this will abort inside the standard library |
| 34 | */ |
| 35 | nifti_image_free(i1); |
| 36 | nifti_image_free(i2); |
| 37 | return 0; |
| 38 | } |