Browse code

dispatcher: replaced some fields init with memset to 0

- safer when adding new fields in structures

Daniel-Constantin Mierla authored on 03/11/2016 13:31:16
Showing 2 changed files
... ...
@@ -206,7 +206,7 @@ int init_data(void)
206 206
 		LM_ERR("Out of memory\n");
207 207
 		return -1;
208 208
 	}
209
-	ds_lists[0] = ds_lists[1] = 0;
209
+	memset(ds_lists, 0, 2*sizeof(ds_set_t*));
210 210
 
211 211
 
212 212
 	p = (int*)shm_malloc(3*sizeof(int));
... ...
@@ -215,6 +215,7 @@ int init_data(void)
215 215
 		LM_ERR("Out of memory\n");
216 216
 		return -1;
217 217
 	}
218
+	memset(p, 0, 3*sizeof(int));
218 219
 
219 220
 	crt_idx = p;
220 221
 	next_idx = p+1;
... ...
@@ -588,10 +589,12 @@ randomize:
588 589
 /*! \brief  compact destinations from sets for fast access */
589 590
 int reindex_dests( ds_set_t* node )
590 591
 {
592
+	int i=0;
593
+	int j=0;
594
+
591 595
 	if ( !node )
592 596
 		return 0;
593 597
 
594
-	int i=0;
595 598
 	for( ;i<2;++i)
596 599
 	{
597 600
 		int rc = reindex_dests( node->next[i] );
... ...
@@ -599,8 +602,6 @@ int reindex_dests( ds_set_t* node )
599 602
 			return rc;
600 603
 	}
601 604
 
602
-	int j;
603
-
604 605
 	ds_dest_t *dp = NULL, *dp0= NULL;
605 606
 
606 607
 	dp0 = (ds_dest_t*)shm_malloc(node->nr*sizeof(ds_dest_t));
... ...
@@ -3029,18 +3030,18 @@ ds_set_t* ds_avl_find( ds_set_t* node, int id )
3029 3030
  */
3030 3031
 void ds_avl_destroy( ds_set_t** node_ptr )
3031 3032
 {
3033
+	ds_set_t *node=NULL;
3034
+	ds_dest_t *dest=NULL;
3035
+	int i=0;
3032 3036
 
3033 3037
 	if ( !node_ptr || !(*node_ptr) )
3034 3038
 		return;
3035 3039
 
3036
-	ds_set_t* node = *node_ptr;
3040
+	node = *node_ptr;
3037 3041
 
3038
-	int i=0;
3039 3042
 	for( ;i<2;++i)
3040 3043
 		ds_avl_destroy( &node->next[i] );
3041 3044
 
3042
-	ds_dest_t *dest = NULL;
3043
-
3044 3045
 	for(dest = node->dlist; dest!= NULL; dest=dest->next)
3045 3046
 	{
3046 3047
 		if(dest->uri.s!=NULL)
... ...
@@ -3062,8 +3063,12 @@ static void avl_rebalance( ds_set_t** path_top, int target );
3062 3063
 
3063 3064
 ds_set_t* ds_avl_insert( ds_set_t** root, int id, int* setn )
3064 3065
 {
3065
-	ds_set_t** rotation_top = root;
3066
-	ds_set_t* node = *root;
3066
+	ds_set_t** rotation_top;
3067
+	ds_set_t* node;
3068
+
3069
+	rotation_top = root;
3070
+	node = *root;
3071
+
3067 3072
 	while (node && id != node->id) {
3068 3073
 		int next_step = (id > node->id);
3069 3074
 		if (!AVL_BALANCED(node)) rotation_top = root;
... ...
@@ -3072,8 +3077,8 @@ ds_set_t* ds_avl_insert( ds_set_t** root, int id, int* setn )
3072 3077
 	}
3073 3078
 	if (!node)
3074 3079
 	{
3075
-		node = shm_malloc(sizeof(*node));
3076
-		node->next[0] = node->next[1] = NULL;
3080
+		node = shm_malloc(sizeof(ds_set_t));
3081
+		memset(node, 0, sizeof(ds_set_t));
3077 3082
 		node->id = id;
3078 3083
 		node->longer = AVL_NEITHER;
3079 3084
 		*root = node;
... ...
@@ -3102,6 +3107,7 @@ static void avl_rebalance_path( ds_set_t* path, int id )
3102 3107
 static ds_set_t* avl_rotate_2( ds_set_t** path_top, int dir )
3103 3108
 {
3104 3109
 	ds_set_t *B, *C, *D, *E;
3110
+
3105 3111
 	B = *path_top;
3106 3112
 	D = B->next[dir];
3107 3113
 	C = D->next[1-dir];
... ...
@@ -3111,12 +3117,14 @@ static ds_set_t* avl_rotate_2( ds_set_t** path_top, int dir )
3111 3117
 	B->next[dir] = C;
3112 3118
 	B->longer = AVL_NEITHER;
3113 3119
 	D->longer = AVL_NEITHER;
3120
+
3114 3121
 	return E;
3115 3122
 }
3116 3123
 
3117 3124
 static ds_set_t* avl_rotate_3( ds_set_t** path_top, int dir, int third )
3118 3125
 {
3119 3126
 	ds_set_t *B, *F, *D, *C, *E;
3127
+
3120 3128
 	B = *path_top;
3121 3129
 	F = B->next[dir];
3122 3130
 	D = F->next[1-dir];
... ...
@@ -3149,8 +3157,11 @@ static ds_set_t* avl_rotate_3( ds_set_t** path_top, int dir, int third )
3149 3157
 
3150 3158
 static void avl_rebalance( ds_set_t** path_top, int id )
3151 3159
 {
3152
-	ds_set_t* path = *path_top;
3160
+	ds_set_t* path;
3153 3161
 	int first, second, third;
3162
+
3163
+	path = *path_top;
3164
+
3154 3165
 	if (AVL_BALANCED(path)) {
3155 3166
 		avl_rebalance_path(path, id);
3156 3167
 		return;
... ...
@@ -180,7 +180,7 @@ typedef struct _ds_set
180 180
 	unsigned int wlist[100];
181 181
 	unsigned int rwlist[100];
182 182
 	struct _ds_set *next[2];
183
-	int longer:2;
183
+	int longer;
184 184
 } ds_set_t;
185 185
 #define AVL_LEFT 0
186 186
 #define AVL_RIGHT 1