NIFTI-Imaging / nifti_clib

C libraries for NIFTI support
Other
33 stars 24 forks source link

Fixed various type punning warnings by using memcpy() #166

Closed seanm closed 1 year ago

seanm commented 1 year ago

Modern compilers optimize memcpy() very well, this will likely produce the same code.

seanm commented 1 year ago

Thanks @hjmjohnson !

afni-rickr commented 1 year ago

Note that this commit has been undone with PR 170. The addressing in 166 does not account for types in indexing. For example char * offsetp = &(((char *)basep + field->offset)[fc]); with float data needs [fc] to offset by floats, not chars.

seanm commented 1 year ago

Note that this commit has been undone with PR 170. The addressing in 166 does not account for types in indexing.

Oh damn, indeed you are right. The many brackets threw me for a loop. Disturbing that no test failed due to this. I'll make a new PR to fix it.

afni-rickr commented 1 year ago

I could add a test for that, something like:

nifti_tool -mod_hdr -new_dim 4 64 64 21 180 0 0 0                \
            -mod_field pixdim "0.0 4.0 4.0 6.0 3.0 1.0 1.0 1.0"  \
            -prefix new_image.nii -infiles MAKE_IM
nifti_tool -disp_hdr -field pixdim -quiet -infiles new_image.nii

If pixdim were set using a variable, that could be checked against the output.

seanm commented 1 year ago

@afni-rickr please see my fix in https://github.com/NIFTI-Imaging/nifti_clib/pull/172