Browse Source

modules_k/dialog When hash_size was smaller then 1, consider this as a value(1 == 2^0)

The 1<<(n-1) check for the power of two smaller than the given number doesn't work for n == 0 (undefined behavior),
so values of dlg_hash_size smaller than 1 where not checked correctly.
Marius Zbihlei 14 years ago
parent
commit
11033b05be
1 changed files with 8 additions and 1 deletions
  1. 8 1
      modules_k/dialog/dialog.c

+ 8 - 1
modules_k/dialog/dialog.c

@@ -603,11 +603,18 @@ static int mod_init(void)
 		return -1;
 	}
 
+	/* sanitize dlg_hash_zie */
+	if (dlg_hash_size < 1){
+		LM_WARN("hash_size is smaller "
+				"then 1  -> rounding from %d to 1\n",
+				dlg_hash_size);
+		dlg_hash_size = 1;
+	}
 	/* initialized the hash table */
 	for( n=0 ; n<(8*sizeof(n)) ; n++) {
 		if (dlg_hash_size==(1<<n))
 			break;
-		if (dlg_hash_size<(1<<n)) {
+		if (n && dlg_hash_size<(1<<n)) {
 			LM_WARN("hash_size is not a power "
 				"of 2 as it should be -> rounding from %d to %d\n",
 				dlg_hash_size, 1<<(n-1));