[Python-Dev] Memory size overflows

Armin Rigo arigo@tunes.org
2002年10月16日 10:11:18 +0200 (CEST)


Hello Guido,
On 2002年10月15日, 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

AltStyle によって変換されたページ (->オリジナル) /