#587914 libnifti1: casting in error messages leads to confusion not clarification

#587914#5
Date:
2010-07-02 16:24:23 UTC
From:
To:
This is an addendum to #587912:
as you can see [1] libnifti spits out messages like

** ERROR: NWAD: wrote only 83065408 of 83065408 bytes to file
before saving/loading
everything 1s
after saving/loading
++ WARNING: nifti_read_buffer(/tmp/ones.nii.gz):
   data bytes needed = 83065408
   data bytes input  = 83065408

or

NWAD: wrote only 1810824704 of 1810824704 bytes to file

which make no sense.  It is due to the use of casting to unsigned and '%u' in
string formatting, while comparison is done on type_t (so it is correct). E.g.:

      if (ss < nim->nbyper * nim->nvox){
         fprintf(stderr,
            "** ERROR: NWAD: wrote only %u of %u bytes to file\n",
            (unsigned)ss, (unsigned)(nim->nbyper * nim->nvox));
         return -1;
      }

imho casting of print arguments should be removed, and string formatting should
be changed from

'%u' (unsigned int) into '%ju', where

       j      A following integer conversion corresponds to an intmax_t or uintmax_t argument.

there is also more appropriate 'z' but it seems to be unadvised, although
might be not really a problem any longer at our times ;)

       z      A following integer conversion corresponds to a size_t or ssize_t argument.  (Linux libc5 has Z with this meaning.  Don't use it.)

so may be to '%zu' to become really proper

Thanks in advance for forwarding it upstream.

Cheers

[1] http://lists.alioth.debian.org/pipermail/pkg-exppsy-pymvpa/2010q2/001168.html

#587914#14
Date:
2010-07-07 15:37:41 UTC
From:
To:
Forwarding upstream response:


We might nevertheless want to have that as a permanent patch in Debian,
but I'm not to keen on doing it.

Michael