Opened 3 years ago

Last modified 3 years ago

#23714 new defect

stop casting small integers to (void *)

Reported by: catalyst Owned by:
Priority: Medium Milestone: Tor: unspecified
Component: Core Tor/Tor Version:
Severity: Normal Keywords: portability technical-debt
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:


Recently someone on IRC seemed confused about some (void *) variables holding the value (void *)1. Converting integers to pointers is implementation defined, and could create invalid pointers. (Any use of an invalid pointer, including assignment or comparison, is undefined behavior.) In addition, it's confusing to people who are less familiar with C.

Many of these uses seem to involve container types that treat a null pointer as an absence of an entry, but in situations there's no meaningful object to point to if the entry is present. Storing the addresses of small statically allocated objects might be better.

Child Tickets

#29895newavoid storing ints in void* in mainloop event dataCore Tor/Tor

Change History (1)

comment:1 Changed 3 years ago by teor

Another option is to make the pointer member into a union type of pointer and integer.
This shouldn't take any extra RAM.

Note: See TracTickets for help on using tickets.