[Python-Dev] Memory size overflows

Armin Rigo arigo@tunes.org
Wed, 16 Oct 2002 10:11:18 +0200 (CEST)


Hello Guido,

On Tue, 15 Oct 2002, Guido van Rossum wrote:
> I like this one, as well as the one using 64-bit precision.  I wonder
> if we could collect a bunch of different macros and make them tunable
> for different platforms?

Doable.  I experimented with some macros that do (unsigned int)*(unsigned
int)->size_t, where the macro to use is selected according to #if's based
on the relative size of int, long and long long.

> (...) The trick will
> to ensure that the macro arguments are used exactly once in all
> versions (otherwise switching macros might unveal a new class of
> bugs).

Harder...

> Apart from *how* to check, there's a variety of cases depending on the
> types of the input and output variables.

True as well... Why are C macros so limited?...

> There are also additions, usually of small constants, which generally
> operate on the size_t.

If we are sure these are small, we can just add without any check if we
reserve a whole range of values for "overflow", e.g. ((size_t)~0x7fff) to
((size_t)~0). Not too clean however.


Armin