This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] [BZ 20628] make mallinfo saturating


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:
~~~
6.3.1.3
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
for overflow).

DJ, Care to make a version 2 of the patch?

-- 
Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]