[sr-dev] git:5.3:99c3ddec: pdb: covert byte-by-byte from buffer to short-int to avoid unalignment compile warning

Henning Westerholt hw at skalatan.de
Wed May 13 15:34:34 CEST 2020


Module: kamailio
Branch: 5.3
Commit: 99c3ddecd7887abed5ab087decdd9ff3712ff545
URL: https://github.com/kamailio/kamailio/commit/99c3ddecd7887abed5ab087decdd9ff3712ff545

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Henning Westerholt <hw at skalatan.de>
Date: 2020-05-13T11:56:48Z

pdb: covert byte-by-byte from buffer to short-int to avoid unalignment compile warning

- GH #2298

(cherry picked from commit 86ebb4eef482b37a3bb8bf033caa4d87fd8aeb87)

---

Modified: src/modules/pdb/pdb.c

---

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

---

diff --git a/src/modules/pdb/pdb.c b/src/modules/pdb/pdb.c
index b72ecf7f29..1ab15af2e7 100644
--- a/src/modules/pdb/pdb.c
+++ b/src/modules/pdb/pdb.c
@@ -189,6 +189,8 @@ static int pdb_msg_format_send(struct pdb_msg *msg,
 }
 
 
+/* two chars to short-int without caring of memory alignment in char buffer */
+#define PDB_BUFTOSHORT(_b, _n) (((short int)_b[_n]) << 8) | (0x00ff & _b[_n+1])
 
 /*!
  * \return 1 if query for the number succeded and the avp with the corresponding carrier id was set,
@@ -199,7 +201,7 @@ static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct
     struct pdb_msg msg;
 	struct timeval tstart, tnow;
 	struct server_item_t *server;
-	short int carrierid, *_id;
+	short int carrierid, _id;
 	short int _idv;
     char buf[sizeof(struct pdb_msg)];
 	size_t reqlen;
@@ -345,8 +347,8 @@ static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct
                                 case PDB_CODE_OK:
                                     msg.bdy.payload[sizeof(struct pdb_bdy) - 1] = '\0';
                                     if (strcmp(msg.bdy.payload, number.s) == 0) {
-                                        _id = (short int *)&(msg.bdy.payload[reqlen]); /* make gcc happy */
-                                        carrierid=ntohs(*_id); /* convert to host byte order */
+                                        _id = PDB_BUFTOSHORT(msg.bdy.payload, reqlen); /* make gcc happy */
+                                        carrierid=ntohs(_id); /* convert to host byte order */
                                         goto found;
                                     }
                                     break;
@@ -368,8 +370,8 @@ static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct
                         default:
                             buf[sizeof(struct pdb_msg) - 1] = '\0';
                             if (strncmp(buf, number.s, number.len) == 0) {
-                                _id = (short int *)&(buf[reqlen]);
-                                carrierid=ntohs(*_id); /* convert to host byte order */
+                                _id = PDB_BUFTOSHORT(buf, reqlen); /* make gcc happy */
+                                carrierid=ntohs(_id); /* convert to host byte order */
                                 goto found;
                             }
                             break;




More information about the sr-dev mailing list