fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-bsc/+/35791?usp=email )


Change subject: abis_nm: fix -Wunused-but-set-variable (bug)
......................................................................

abis_nm: fix -Wunused-but-set-variable (bug)

clang warns us about 'len' being set, but not used:  And this is

  abis_nm.c:2172:10: warning: variable 'len' set but not used 
[-Wunused-but-set-variable]
        uint8_t len = att_len;
                ^

This is actually a bug, because in the case of NACK we append 2 more
bytes {NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP}, and we need to
pass the final length to fill_om_fom_hdr(), including those optional
two bytes.  Passing 'att_len' (length of 'attr') is wrong.

Change-Id: I3ca8e761fdf99dd498a979ccc9d53c6c3e03e2cc
---
M include/osmocom/bsc/abis_nm.h
M src/osmo-bsc/abis_nm.c
2 files changed, 32 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/91/35791/1

diff --git a/include/osmocom/bsc/abis_nm.h b/include/osmocom/bsc/abis_nm.h
index 7f1ec74..59a6dc9 100644
--- a/include/osmocom/bsc/abis_nm.h
+++ b/include/osmocom/bsc/abis_nm.h
@@ -86,7 +86,8 @@
 int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, uint8_t *attr, int 
attr_len);
 int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, uint8_t chan_comb);
 int abis_nm_sw_act_req_ack(struct gsm_bts *bts, uint8_t obj_class, uint8_t i1,
-                       uint8_t i2, uint8_t i3, int nack, uint8_t *attr, int 
att_len);
+                          uint8_t i2, uint8_t i3, int nack,
+                          const uint8_t *attr, int attr_len);
 int abis_nm_raw_msg(struct gsm_bts *bts, int len, uint8_t *msg);
 int abis_nm_event_reports(struct gsm_bts *bts, int on);
 int abis_nm_reset_resource(struct gsm_bts *bts);
diff --git a/src/osmo-bsc/abis_nm.c b/src/osmo-bsc/abis_nm.c
index 81a0272..120701b 100644
--- a/src/osmo-bsc/abis_nm.c
+++ b/src/osmo-bsc/abis_nm.c
@@ -2164,12 +2164,17 @@
 }

 int abis_nm_sw_act_req_ack(struct gsm_bts *bts, uint8_t obj_class, uint8_t i1,
-                       uint8_t i2, uint8_t i3, int nack, uint8_t *attr, int 
att_len)
+                          uint8_t i2, uint8_t i3, int nack,
+                          const uint8_t *attr, int attr_len)
 {
        struct abis_om_hdr *oh;
        struct msgb *msg = nm_msgb_alloc();
        uint8_t msgtype = NM_MT_SW_ACT_REQ_ACK;
-       uint8_t len = att_len;
+       uint8_t len;
+
+       if (attr_len < 0)
+               return -EINVAL;
+       len = attr_len;

        if (nack) {
                len += 2;
@@ -2177,12 +2182,10 @@
        }

        oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE);
-       fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3);
+       fill_om_fom_hdr(oh, len, msgtype, obj_class, i1, i2, i3);

-       if (attr) {
-               uint8_t *ptr = msgb_put(msg, att_len);
-               memcpy(ptr, attr, att_len);
-       }
+       if (attr != NULL && attr_len > 0)
+               memcpy(msgb_put(msg, attr_len), attr, attr_len);
        if (nack)
                msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP);


--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/35791?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I3ca8e761fdf99dd498a979ccc9d53c6c3e03e2cc
Gerrit-Change-Number: 35791
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-MessageType: newchange

Reply via email to