From 7032754482cc88c4a9cce424a4717de7165fee17 Mon Sep 17 00:00:00 2001 From: Juha Hyttinen Date: Tue, 29 Sep 2020 13:05:01 +0300 Subject: [PATCH] Dereference before null (nil) check Change-Id: Iba704e5fcb0b9091ec35601480475021c60372b5 Signed-off-by: Juha Hyttinen --- pkg/xapp/rmr.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pkg/xapp/rmr.go b/pkg/xapp/rmr.go index 9f988dc..e27d46e 100755 --- a/pkg/xapp/rmr.go +++ b/pkg/xapp/rmr.go @@ -313,6 +313,10 @@ func (m *RMRClient) SendWithRetry(params *RMRParams, isRts bool, to time.Duratio func (m *RMRClient) CopyBuffer(params *RMRParams) *C.rmr_mbuf_t { + if params == nil { + return nil + } + payLen := len(params.Payload) if params.PayloadLen != 0 { payLen = params.PayloadLen @@ -337,20 +341,21 @@ func (m *RMRClient) CopyBuffer(params *RMRParams) *C.rmr_mbuf_t { datap := C.CBytes(params.Payload) defer C.free(datap) - if params != nil { - if params.Meid != nil { - b := make([]byte, int(C.RMR_MAX_MEID)) - copy(b, []byte(params.Meid.RanName)) - C.rmr_bytes2meid(txBuffer, (*C.uchar)(unsafe.Pointer(&b[0])), C.int(len(b))) - } - xidLen := len(params.Xid) - if xidLen > 0 && xidLen <= C.RMR_MAX_XID { - b := make([]byte, int(C.RMR_MAX_XID)) - copy(b, []byte(params.Xid)) - C.rmr_bytes2xact(txBuffer, (*C.uchar)(unsafe.Pointer(&b[0])), C.int(len(b))) - } + if params.Meid != nil { + b := make([]byte, int(C.RMR_MAX_MEID)) + copy(b, []byte(params.Meid.RanName)) + C.rmr_bytes2meid(txBuffer, (*C.uchar)(unsafe.Pointer(&b[0])), C.int(len(b))) } + + xidLen := len(params.Xid) + if xidLen > 0 && xidLen <= C.RMR_MAX_XID { + b := make([]byte, int(C.RMR_MAX_XID)) + copy(b, []byte(params.Xid)) + C.rmr_bytes2xact(txBuffer, (*C.uchar)(unsafe.Pointer(&b[0])), C.int(len(b))) + } + C.write_bytes_array(txBuffer.payload, datap, txBuffer.len) + return txBuffer } -- 2.16.6