[Insight-developers] nrrd assumptions and signed overflow
Sean McBride
sean at rogue-research.com
Fri Nov 25 18:17:41 EST 2011
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
More information about the Insight-developers
mailing list