Browse code

core: flags - use unsigned literal for bit shifting operations

Daniel-Constantin Mierla authored on 28/11/2021 09:39:02
Showing 1 changed files
... ...
@@ -43,12 +43,12 @@ static flag_t sflags = 0;
43 43
 
44 44
 
45 45
 int setflag( struct sip_msg* msg, flag_t flag ) {
46
-	msg->flags |= 1 << flag;
46
+	msg->flags |= 1u << flag;
47 47
 	return 1;
48 48
 }
49 49
 
50 50
 int resetflag( struct sip_msg* msg, flag_t flag ) {
51
-	msg->flags &= ~ (1 << flag);
51
+	msg->flags &= ~ (1u << flag);
52 52
 	return 1;
53 53
 }
54 54
 
... ...
@@ -58,7 +58,7 @@ int resetflags( struct sip_msg* msg, flag_t flags ) {
58 58
 }
59 59
 
60 60
 int isflagset( struct sip_msg* msg, flag_t flag ) {
61
-	return (msg->flags & (1<<flag)) ? 1 : -1;
61
+	return (msg->flags & (1u<<flag)) ? 1 : -1;
62 62
 }
63 63
 
64 64
 int flag_in_range( flag_t flag ) {
... ...
@@ -79,21 +79,21 @@ int setsflagsval(flag_t val)
79 79
 
80 80
 int setsflag(flag_t flag)
81 81
 {
82
-	sflags |= 1 << flag;
82
+	sflags |= 1u << flag;
83 83
 	return 1;
84 84
 }
85 85
 
86 86
 
87 87
 int resetsflag(flag_t flag)
88 88
 {
89
-	sflags &= ~ (1 << flag);
89
+	sflags &= ~ (1u << flag);
90 90
 	return 1;
91 91
 }
92 92
 
93 93
 
94 94
 int issflagset(flag_t flag)
95 95
 {
96
-	return (sflags & (1<<flag)) ? 1 : -1;
96
+	return (sflags & (1u<<flag)) ? 1 : -1;
97 97
 }
98 98
 
99 99
 
... ...
@@ -126,7 +126,7 @@ static unsigned char registered_flags[MAX_FLAG+1];
126 126
 void init_named_flags()
127 127
 {
128 128
 	int r;
129
-	
129
+
130 130
 	for (r=0; r<FLAGS_NAME_HASH_ENTRIES; r++)
131 131
 		clist_init(&name2flags[r], next, prev);
132 132
 }
... ...
@@ -149,7 +149,7 @@ inline static struct flag_entry* flag_search(struct flag_hash_head* lst,
149 149
 												char* name, int len)
150 150
 {
151 151
 	struct flag_entry* fe;
152
-	
152
+
153 153
 	clist_foreach(lst, fe, next){
154 154
 		if ((fe->name.len==len) && (memcmp(fe->name.s, name, len)==0)){
155 155
 			/* found */
... ...
@@ -176,7 +176,7 @@ inline static struct flag_entry* get_flag_entry(char* name, int len)
176 176
 int get_flag_no(char* name, int len)
177 177
 {
178 178
 	struct flag_entry* fe;
179
-	
179
+
180 180
 	fe=get_flag_entry(name, len);
181 181
 	return (fe)?fe->no:-1;
182 182
 }
... ...
@@ -184,7 +184,7 @@ int get_flag_no(char* name, int len)
184 184
 
185 185
 
186 186
 /* resgiter a new flag name and associates it with pos
187
- * pos== -1 => any position will do 
187
+ * pos== -1 => any position will do
188 188
  * returns flag pos on success (>=0)
189 189
  *         -1  flag is an alias for an already existing flag
190 190
  *         -2  flag already registered
... ...
@@ -199,7 +199,7 @@ int register_flag(char* name, int pos)
199 199
 	static unsigned int crt_flag=0;
200 200
 	unsigned int last_flag;
201 201
 	unsigned int h;
202
-	
202
+
203 203
 	len=strlen(name);
204 204
 	h=get_hash1_raw(name, len) & (FLAGS_NAME_HASH_ENTRIES-1);
205 205
 	/* check if the name already exists */
... ...
@@ -235,7 +235,7 @@ int register_flag(char* name, int pos)
235 235
 		}
236 236
 	}
237 237
 	registered_flags[pos]++;
238
-	
238
+
239 239
 	e=pkg_malloc(sizeof(struct flag_entry));
240 240
 	if (e==0){
241 241
 		PKG_MEM_ERROR;
... ...
@@ -259,7 +259,7 @@ int setxflag(struct sip_msg* msg, flag_t flag)
259 259
 	uint32_t fb;
260 260
 	fi = flag / (sizeof(flag_t)*CHAR_BIT);
261 261
 	fb = flag % (sizeof(flag_t)*CHAR_BIT);
262
-	msg->xflags[fi] |= 1 << fb;
262
+	msg->xflags[fi] |= 1u << fb;
263 263
 	return 1;
264 264
 }
265 265
 
... ...
@@ -272,7 +272,7 @@ int resetxflag(struct sip_msg* msg, flag_t flag)
272 272
 	uint32_t fb;
273 273
 	fi = flag / (sizeof(flag_t)*CHAR_BIT);
274 274
 	fb = flag % (sizeof(flag_t)*CHAR_BIT);
275
-	msg->xflags[fi] &= ~ (1 << fb);
275
+	msg->xflags[fi] &= ~ (1u << fb);
276 276
 	return 1;
277 277
 }
278 278
 
... ...
@@ -285,5 +285,5 @@ int isxflagset(struct sip_msg* msg, flag_t flag)
285 285
 	uint32_t fb;
286 286
 	fi = flag / (sizeof(flag_t)*CHAR_BIT);
287 287
 	fb = flag % (sizeof(flag_t)*CHAR_BIT);
288
-	return (msg->xflags[fi] & (1<<fb)) ? 1 : -1;
288
+	return (msg->xflags[fi] & (1u<<fb)) ? 1 : -1;
289 289
 }