[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Set operations on bool-vectors
From: |
Daniel Colascione |
Subject: |
Re: Set operations on bool-vectors |
Date: |
Sat, 21 Sep 2013 00:38:43 -0700 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 |
On 9/21/13 12:36 AM, Andreas Schwab wrote:
> Daniel Colascione <address@hidden> writes:
>
>> +static
>> +ptrdiff_t
>> +bool_vector_payload_bytes (EMACS_INT length)
>> +{
>> + EMACS_INT exact_needed_bytes;
>> + EMACS_INT needed_bytes;
>> +
>> + exact_needed_bytes = (length + CHAR_BIT - 1) / CHAR_BIT;
>> + needed_bytes = (exact_needed_bytes + sizeof (size_t) - 1)
>> + / sizeof (size_t);
>> +
>> + needed_bytes *= sizeof (size_t);
>
> Please check for overflow.
It can't overflow. The initial number of bits comes from a Lisp
integer, which has a bit less range than an int. What exactly is the
routine supposed to do if the value overflows?
> Also, the return type should be EMACS_INT,
> not ptrdiff_t.
Well, vector_nbytes works with ptrdiff_t, and the allocation code works
in EMACS_INT. I'm not sure the distinction actually matters in this case.
signature.asc
Description: OpenPGP digital signature