Opened 5 months ago

Closed 3 months ago

#22521 closed defect (implemented)

use offsetof() instead of rolling our own

Reported by: catalyst Owned by: catalyst
Priority: Medium Milestone: Tor: 0.3.2.x-final
Component: Core Tor/Tor Version:
Severity: Normal Keywords:
Cc: neel@… Actual Points:
Parent ID: Points:
Reviewer: Sponsor: Sponsor8-can

Description

src/common/util.h defines a STRUCT_OFFSET() macro that effectively duplicates offsetof(), which has been available in stddef.h since C89. The non-GCC version of STRUCT_OFFSET() does pointer arithmetic on null pointers, which is undefined behavior.

We should use the standard offsetof() macro instead, unless there's some reason we still need to support platforms that lack it.

Child Tickets

Attachments (1)

tor_offsetof_0001.patch (16.3 KB) - added by neel 3 months ago.
Patch to change STRUCT_OFFSET to offsetof()

Download all attachments as: .zip

Change History (6)

comment:1 Changed 3 months ago by catalyst

Sponsor: Sponsor8-can

comment:2 Changed 3 months ago by neel

Cc: neel@… added

Changed 3 months ago by neel

Attachment: tor_offsetof_0001.patch added

Patch to change STRUCT_OFFSET to offsetof()

comment:3 Changed 3 months ago by neel

I have created a patch for this in the file tor_offsetof_0001.patch​.

comment:4 Changed 3 months ago by nickm

Status: newneeds_review

comment:5 Changed 3 months ago by nickm

Resolution: implemented
Status: needs_reviewclosed

lgtm; merged to master. Thank you!

Note: See TracTickets for help on using tickets.