This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] [BZ 20628] make mallinfo saturating
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Paul Eggert <eggert at cs dot ucla dot edu>, DJ Delorie <dj at redhat dot com>, libc-alpha at sourceware dot org
- Date: Wed, 28 Sep 2016 16:26:13 -0400
- Subject: Re: [PATCH] [BZ 20628] make mallinfo saturating
- Authentication-results: sourceware.org; auth=none
- References: <firstname.lastname@example.org> <email@example.com>
On 09/27/2016 03:07 PM, Paul Eggert wrote:
> It would be more backward-compatible to represent minor overflows as
> negative numbers that are equivalent to the correct answers modulo
> (UINT_MAX + 1). That way, callers can continue to retrieve the
> correct values by casting int to unsigned. The code can use -1 to
> represent a value greater than UINT_MAX. This all should be doable
> just as efficiently as the proposed patch.
Agreed, I had not considered that case. It would certainly make the
interface as useful as it could be with a 32-bit address space, but
it would still be mostly useless on a 64-bit system (even with 48-bit VA).
I just double checked that C11 does continue to contain the clause
that allows the conversion to work:
Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
subtracting one more than the maximum value that can be represented in the new type
until the value is in the range of the new type.60)
60) The rules describe arithmetic on the mathematical value, not the value of a given type of expression.
This way you could cast the values to 'unsigned int' and know you had
a valid result as long as it was less than '(unsigned int)-1' (reserved
DJ, Care to make a version 2 of the patch?