[Developers] [Patches] fix to integer overflow bug in PUGH

Erik Schnetter schnetter at cct.lsu.edu
Sat Apr 7 04:18:37 CDT 2007


On Apr 7, 2007, at 09:09:45, Jonathan Thornburg wrote:

> [[how to print a size_t]]
> David Rideout suggested:
>> How about casting it to an unsigned long instead?  (Just because in
>> principle one may be interested in the exact value.)
>
> On Sat, 7 Apr 2007, Erik Schnetter wrote:
>> That works only when you can guarantee that a size_t fits into an  
>> unsigned
>> long.  This may not be true in general.  You could use unsigned  
>> long long
>> instead, but this type does not exist on all platforms.
>>
>> If the value fits into a double, i.e., if you have less than about  
>> 10^15, then
>> a double is exact.
>
> C99 <stdint.h> defines the types   intmax_t  and  uintmax_t  for just
> this purpose (they're guaranteed to be big enough to hold any
> integer/unsigned-integer type in the language standard), with
> corresponding C99 printf formats   '%jd   or   %ju   .

Cactus doesn't yet require a C99 compiler.  While I tend to use C99  
features in my own thorns, I don't know whether we should do that in  
PUGH if there is an easy work-around.

> What I'm not clear on, however, is whether  intmax_t  is guaranteed
> to be big enough to hold a  long long  .

intmax_t is by definition large enough to hold a long long; you mean  
size_t.  I believe it is large enough for a size_t as well.  (It may  
not be large enough to hold a void *, but this is irrelevant here.)

> On the other hand, C99 also guarantees that 'long long' and
> 'unsigned long long' exist (i.e. they're not syntax errors).  On some
> lame system they might not be any bigger than 'long' and 'unsigned  
> long'
> respectively, though.
>
> Overall, I like Erik's proposal of converting to a  double .
> An IEEE double  will hold any integer up to 53 bits exactly
> and I strongly suspect that if there are any computers in the world
> with 2^53 bytes of addressable memory, they're reserved for spooks
> designing H-bombs or pattern-matching every {E-mail,fax,phone call}
> in the world, and not available for Cactus.

I've just installed Cactus on a system (www.lite3d.com) which has  
2^42 bytes of addressable memory.  In words these are four Terabytes.  
This is a visualisation machine called "Beast" in Lafayette, Louisiana.

-erik

-- 
Erik Schnetter <schnetter at cct.lsu.edu>

My email is as private as my paper mail.  I therefore support encrypting
and signing email messages.  Get my PGP key from www.keyserver.net.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://www.cactuscode.org/pipermail/developers/attachments/20070407/ecd32c23/attachment.bin 


More information about the Developers mailing list