[PATCH] posix: Fix -Warray-bounds instances building timer_create [BZ #26687]
Florian Weimer
fweimer@redhat.com
Tue Oct 6 14:13:28 GMT 2020
* Adhemerval Zanella:
> On 06/10/2020 05:21, Florian Weimer wrote:
>> * Florian Weimer:
>>
>>> * Adhemerval Zanella via Libc-alpha:
>>>
>>>> This patch fixes both issues by embedding the information whether
>>>> the timer if a SIGEV_THREAD in the returned 'timer_t'. For
>>>> !SIGEV_THREAD, the resulting 'timer_t' is the returned kernel timer
>>>> identifer (kernel_timer_t), while for SIGEV_THREAD it uses the fact
>>>> malloc returns at least _Alignof (max_align_t) pointers plus that
>>>> valid kernel_timer_t are always positive to set MSB bit of the returned
>>>> 'timer_t' to indicate the timer handles a SIGEV_THREAD.
>>>
>>> LSB, not MSB, right?
>>
>> Ah, no, it is the MSB.
>>
>> I think using the LSB is generally more efficient for this because it is
>> easier to manipulate. In this scenario, pointers would be unencoded,
>> and a kernel_timer_t value ktid would be encoded as 2 * kdid + 1. But I
>> guess the difference does not matter much.
>
> I think either way works and it should be easy to change since all the
> logic to convert from 'timer_t' to 'kernel_timer_t' and check if the
> timer is a SIGEV_THREAD is at kernel-posix-timers.h.
Except the kernel-ID-to-timer_t translation. The series of casts is
currently open-coded. Maybe you could add an inline helper function for
that, too?
Thanks,
Florian
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
More information about the Libc-alpha
mailing list