Browse code

ctl: use unsigned int for bit left shifting

- deal with runtime error: left shift of X by N places cannot be represented in type 'int'

Daniel-Constantin Mierla authored on 14/11/2021 19:23:08
Showing 1 changed files
... ...
@@ -215,12 +215,15 @@ inline static unsigned char* binrpc_write_int(	unsigned char* p,
215 215
 												int i, int *len)
216 216
 {
217 217
 	int size;
218
+	unsigned int u;
218 219
 
219
-	for (size=4; size && ((i & (0xffu<<24))==0); i<<=8, size--);
220
+	u = (unsigned int)i;
221
+
222
+	for (size=4; size && ((u & (0xffu<<24))==0); u<<=8, size--);
220 223
 	*len=size;
221 224
 	for(; (p<end) && (size); p++, size--){
222
-		*p=(unsigned char)(i>>24);
223
-		i<<=8;
225
+		*p=(unsigned char)(u>>24);
226
+		u<<=8;
224 227
 	}
225 228
 	return p;
226 229
 }
... ...
@@ -515,24 +518,28 @@ static inline int binrpc_addfault(	struct binrpc_pkt* pkt,
515 518
 
516 519
 static inline unsigned char* binrpc_read_int(	int* i,
517 520
 												int len,
518
-												unsigned char* s, 
521
+												unsigned char* s,
519 522
 												unsigned char* end,
520 523
 												int *err
521 524
 												)
522 525
 {
523 526
 	unsigned char* start;
524
-	
527
+	unsigned int u;
528
+
525 529
 	start=s;
526 530
 	*i=0;
531
+	u = 0;
527 532
 	*err=0;
528 533
 	for(;len>0; len--, s++){
529 534
 		if (s>=end){
530 535
 			*err=E_BINRPC_MORE_DATA;
536
+			*i = (int)u;
531 537
 			return start;
532 538
 		}
533
-		*i<<=8;
534
-		*i|=*s;
539
+		u<<=8;
540
+		u|=*s;
535 541
 	};
542
+	*i = (int)u;
536 543
 	return s;
537 544
 }
538 545