[Insight-developers] nrrd assumptions and signed overflow

David Cole david.cole at kitware.com
Sat Nov 26 11:04:06 EST 2011


Ask on the "teem" mailing list. They're complete nrrd nerds over there... :-P


On Fri, Nov 25, 2011 at 6:17 PM, Sean McBride <sean at rogue-research.com> wrote:
> Hi all,
>
> Many of the "nrrd" tests are failing on my clang dashboard, and I took a look at why... There is this function:
>
> ****** nrrdSanity
> **
> ** makes sure that all the basic assumptions of nrrd hold for
> ** the architecture/etc which we're currently running on.
> **
> ** returns 1 if all is okay, 0 if there is a problem
>
> which does this:
>
>  tmpLLI = NRRD_LLONG_MAX;
>  if (tmpLLI != NRRD_LLONG_MAX) {
>    return 0;
>  }
>
>  tmpLLI += 1; // problem here
>
>  if (NRRD_LLONG_MIN != tmpLLI) {
>    return 0;
>  }
>  tmpULLI = NRRD_ULLONG_MAX;
>
> "tmpLLI" is a signed long long.  They are adding 1 to the largest possible signed long long, and signed overflow is undefined in C/C++.  The compiler can do whatever it wants in the case of undefined behaviour, and with the flags I'm using it deliberately generates an illegal instruction.
>
> I stopped investigating here, since from the comments of this method, it seems that nrrd requires/expects that the compiler wraps signed values.
>
> Anyone know this nrrd stuff well?
>
> Cheers,
>
> --
> ____________________________________________________________
> Sean McBride, B. Eng                 sean at rogue-research.com
> Rogue Research                        www.rogue-research.com
> Mac Software Developer              Montréal, Québec, Canada
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers
>


More information about the Insight-developers mailing list