Skip to content

Commit 2ca0158

Browse files
chipitsinewtarreau
authored andcommitted
CLEANUP: use "offsetof" where appropriate
let's use the C library macro "offsetof"
1 parent b5efe79 commit 2ca0158

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,12 @@ static void delete_entry(struct cache_entry *del_entry)
425425

426426
static inline struct shared_context *shctx_ptr(struct cache *cache)
427427
{
428-
return (struct shared_context *)((unsigned char *)cache - ((struct shared_context *)NULL)->data);
428+
return (struct shared_context *)((unsigned char *)cache - offsetof(struct shared_context, data));
429429
}
430430

431431
static inline struct shared_block *block_ptr(struct cache_entry *entry)
432432
{
433-
return (struct shared_block *)((unsigned char *)entry - ((struct shared_block *)NULL)->data);
433+
return (struct shared_block *)((unsigned char *)entry - offsetof(struct shared_block, data));
434434
}
435435

436436

src/ssl_sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4205,7 +4205,7 @@ static inline void sh_ssl_sess_free_blocks(struct shared_block *first, struct sh
42054205
/* return first block from sh_ssl_sess */
42064206
static inline struct shared_block *sh_ssl_sess_first_block(struct sh_ssl_sess_hdr *sh_ssl_sess)
42074207
{
4208-
return (struct shared_block *)((unsigned char *)sh_ssl_sess - ((struct shared_block *)NULL)->data);
4208+
return (struct shared_block *)((unsigned char *)sh_ssl_sess - offsetof(struct shared_block, data));
42094209

42104210
}
42114211

0 commit comments

Comments
 (0)