Browse code

core: unsigned literal for 1 used in left shifting for script callbacks

- GH #2897

Daniel-Constantin Mierla authored on 25/10/2021 13:11:29
Showing 2 changed files
... ...
@@ -78,11 +78,11 @@ int register_script_cb( cb_function f, unsigned int flags, void *param )
78 78
 	int	i;
79 79
 
80 80
 	/* type checkings */
81
-	if ( (flags&((1<<SCRIPT_CB_NUM)-1))==0 ) {
81
+	if ( (flags&((1u<<SCRIPT_CB_NUM)-1))==0 ) {
82 82
 		LM_BUG("callback flag not specified\n");
83 83
 		return -1;
84 84
 	}
85
-	if ( (flags&(~(PRE_SCRIPT_CB|POST_SCRIPT_CB))) >= 1<<SCRIPT_CB_NUM ) {
85
+	if ( (flags&(~(PRE_SCRIPT_CB|POST_SCRIPT_CB))) >= 1u<<SCRIPT_CB_NUM ) {
86 86
 		LM_BUG("unsupported callback flags: %u\n",
87 87
 			flags);
88 88
 		return -1;
... ...
@@ -102,7 +102,7 @@ int register_script_cb( cb_function f, unsigned int flags, void *param )
102 102
 	 * (as many times as many flags are set)
103 103
 	 */
104 104
 	for (i=0; i<SCRIPT_CB_NUM; i++) {
105
-		if ((flags&(1<<i)) == 0)
105
+		if ((flags&(1u<<i)) == 0)
106 106
 			continue;
107 107
 		if (add_callback(&cb_array[i], f, param) < 0)
108 108
 			goto add_error;
... ...
@@ -155,7 +155,7 @@ int exec_pre_script_cb( struct sip_msg *msg, enum script_cb_type type)
155 155
 		return 0;
156 156
 	}
157 157
 
158
-	flags = PRE_SCRIPT_CB | (1<<(type-1));
158
+	flags = PRE_SCRIPT_CB | (1u<<(type-1));
159 159
 	for (cb=pre_script_cb[type-1]; cb ; cb=cb->next ) {
160 160
 		/* stop on error */
161 161
 		if (cb->cbf(msg, flags, cb->param)==0)
... ...
@@ -177,7 +177,7 @@ int exec_post_script_cb( struct sip_msg *msg, enum script_cb_type type)
177 177
 		return 1;
178 178
 	}
179 179
 
180
-	flags = POST_SCRIPT_CB | (1<<(type-1));
180
+	flags = POST_SCRIPT_CB | (1u<<(type-1));
181 181
 	for (cb=post_script_cb[type-1]; cb ; cb=cb->next){
182 182
 		cb->cbf(msg, flags, cb->param);
183 183
 	}
... ...
@@ -33,8 +33,8 @@
33 33
 typedef int (cb_function)(struct sip_msg *msg, unsigned int flags, void *param);
34 34
 
35 35
 
36
-#define PRE_SCRIPT_CB    (1<<30)
37
-#define POST_SCRIPT_CB   (1<<31)
36
+#define PRE_SCRIPT_CB    (1u<<30)
37
+#define POST_SCRIPT_CB   (1u<<31)
38 38
 
39 39
 /* Pre- and post-script callback flags. Use these flags to register
40 40
  * for the callbacks, and to check the type of the callback from the