Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low: fix compiler's complaints about possibly unaligned pointer access #80

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/booth.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ struct attr_msg {

/* GEO attributes
* attributes should be regularly updated.
* Regarding alignment and respective layout, see the commentary
* at struct booth_site.
*/
struct geo_attr {
/** Update timestamp. */
Expand All @@ -171,7 +173,7 @@ struct geo_attr {
/** Who set it (currently unused)
struct booth_site *origin;
*/
} __attribute__((packed));
} __attribute__((packed, aligned(_Alignof(timetype))));

struct hmac {
/** hash id, currently set to constant BOOTH_HASH */
Expand Down Expand Up @@ -282,6 +284,25 @@ typedef enum {
/** @{ */

struct booth_site {
/* for a packed struct, we'd rather put subjects to address-of
operator first, in biggest-to-lowest _Alignof(typeof(<member>))
order, since then it's enough to "just" align whole-struct
boundaries to _Alignof(<first member>) and the misaligned
pointer access is no longer at risk;
alternatively, we may explicitly align respective members
at their original in-struct offsets, but that would just
introduce additional paddings */
time_t last_recv;
union {
struct sockaddr_in sa4;
struct sockaddr_in6 sa6;
};

/* data locality related to the above use-by-reference members */
unsigned short family;
int saddrlen;
int addrlen;

/** Calculated ID. See add_site(). */
int site_id;
int type;
Expand All @@ -300,16 +321,8 @@ struct booth_site {
int index;
uint64_t bitmask;

unsigned short family;
union {
struct sockaddr_in sa4;
struct sockaddr_in6 sa6;
};
int saddrlen;
int addrlen;

/** statistics */
time_t last_recv;
/* time_t last_recv; // previous location */
unsigned int sent_cnt;
unsigned int sent_err_cnt;
unsigned int resend_cnt;
Expand All @@ -321,7 +334,7 @@ struct booth_site {
/** last timestamp seen from this site */
uint32_t last_secs;
uint32_t last_usecs;
} __attribute__((packed));
} __attribute__((packed, aligned(_Alignof(time_t))));



Expand Down