On 8/25/25 13:23, Jan Beulich wrote:
> On 24.08.2025 19:27, Dmytro Prokopchuk1 wrote:
>> MISRA C Rule 11.3 states: "A cast shall not be performed between a pointer
>> to object type and a pointer to a different object type."
>>
>> Violations of this rule arise due to the 'container_of()' macro, which casts
>> a member of a structure to its containing structure:
>>      container_of(ptr, type, member) ({                             \
>>             typeof_field(type, member) *__mptr = (ptr);             \
>>             (type *)( (char *)__mptr - offsetof(type,member) );})
>>
>> The 'container_of()' macro is safe because it relies on the standardized and
>> well-defined 'offsetof()' macro to calculate the memory address of the
>> containing structure, while assuming proper alignment and ensuring no
>> undefined behavior, provided that the input pointer is valid and points to
>> the specified member.
> 
> I may have said so before: This all reads okay to me, just that I'm unsure
> it would actually be convincing to an assessor. The "provided that ..." is
> a pretty strong requirement, which isn't overly hard to get wrong. Stefano,
> Nicola - what's your take here?
> 
> Jan

Stefano, Nicola,

gentle reminder.

Dmytro.

Reply via email to