Skip to content

Commit 6a07292

Browse files
committedNov 28, 2020
Refactor lock_set_alloc() to not trigger unaligned access warning on arm32:
net/../lock_alloc.h: In function lock_set_alloc net/../lock_alloc.h:70:13: warning: cast increases required alignment of target type [-Wcast-align] This also produces cleaner code and it might be also bit faster too.
1 parent 3fad847 commit 6a07292

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
 

‎lock_alloc.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@
6262

6363
inline static gen_lock_set_t* lock_set_alloc(int n)
6464
{
65-
gen_lock_set_t* ls;
66-
ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t)+n*sizeof(gen_lock_t));
67-
if (ls==0){
65+
struct {
66+
gen_lock_set_t set;
67+
gen_lock_t _locks[0];
68+
} *ls;
69+
70+
ls=shm_malloc(sizeof(*ls)+n*sizeof(ls->_locks[0]));
71+
if (ls==NULL){
6872
LM_CRIT("no more shm memory\n");
6973
}else{
70-
ls->locks=(gen_lock_t*)((char*)ls+sizeof(gen_lock_set_t));
71-
ls->size=n;
74+
ls->set.locks=ls->_locks;
75+
ls->set.size=n;
7276
}
73-
return ls;
77+
return &(ls->set);
7478
}
7579

7680
#define lock_set_dealloc(lock_set) shm_free((void*)lock_set)

0 commit comments

Comments
 (0)
Please sign in to comment.