[sr-dev] git:master:b3e8d030: ctl: use unsigned int for bit left shifting

Daniel-Constantin Mierla miconda at gmail.com
Sun Nov 14 20:25:00 CET 2021


Module: kamailio
Branch: master
Commit: b3e8d03038402dec78b4845255f34862407983c9
URL: https://github.com/kamailio/kamailio/commit/b3e8d03038402dec78b4845255f34862407983c9

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-11-14T20:23:08+01:00

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'

---

Modified: src/modules/ctl/binrpc.h

---

Diff:  https://github.com/kamailio/kamailio/commit/b3e8d03038402dec78b4845255f34862407983c9.diff
Patch: https://github.com/kamailio/kamailio/commit/b3e8d03038402dec78b4845255f34862407983c9.patch

---

diff --git a/src/modules/ctl/binrpc.h b/src/modules/ctl/binrpc.h
index bd7e2cb9c5..cb7204fffd 100644
--- a/src/modules/ctl/binrpc.h
+++ b/src/modules/ctl/binrpc.h
@@ -215,12 +215,15 @@ inline static unsigned char* binrpc_write_int(	unsigned char* p,
 												int i, int *len)
 {
 	int size;
+	unsigned int u;
 
-	for (size=4; size && ((i & (0xffu<<24))==0); i<<=8, size--);
+	u = (unsigned int)i;
+
+	for (size=4; size && ((u & (0xffu<<24))==0); u<<=8, size--);
 	*len=size;
 	for(; (p<end) && (size); p++, size--){
-		*p=(unsigned char)(i>>24);
-		i<<=8;
+		*p=(unsigned char)(u>>24);
+		u<<=8;
 	}
 	return p;
 }
@@ -515,24 +518,28 @@ static inline int binrpc_addfault(	struct binrpc_pkt* pkt,
 
 static inline unsigned char* binrpc_read_int(	int* i,
 												int len,
-												unsigned char* s, 
+												unsigned char* s,
 												unsigned char* end,
 												int *err
 												)
 {
 	unsigned char* start;
-	
+	unsigned int u;
+
 	start=s;
 	*i=0;
+	u = 0;
 	*err=0;
 	for(;len>0; len--, s++){
 		if (s>=end){
 			*err=E_BINRPC_MORE_DATA;
+			*i = (int)u;
 			return start;
 		}
-		*i<<=8;
-		*i|=*s;
+		u<<=8;
+		u|=*s;
 	};
+	*i = (int)u;
 	return s;
 }
 




More information about the sr-dev mailing list