fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/27004 )


Change subject: gsm_utils: get rid of calloc() / free() in gsm_septets2octets()
......................................................................

gsm_utils: get rid of calloc() / free() in gsm_septets2octets()

Given that 'septet_len' is of type 'uint8_t', plus one optional
padding octet, the maximum buffer size is 256.  No need to use
the heap for that, a buffer on the stack is enough in this case.

Change-Id: Id2bb31b4d00bb91d3dcc302910e5d2da95be9a25
---
M src/gsm/gsm_utils.c
1 file changed, 1 insertion(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/04/27004/1

diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index f8bb58e..ba24291 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -322,10 +322,10 @@
  *  \returns number of bytes used in \a result */
 int gsm_septet_pack(uint8_t *result, const uint8_t *rdata, size_t septet_len, 
uint8_t padding)
 {
+       uint8_t data[UINT8_MAX + 1] = { 0 };
        int i = 0, z = 0;
        uint8_t cb, nb;
        int shift = 0;
-       uint8_t *data = calloc(septet_len + 1, sizeof(uint8_t));

        if (padding) {
                shift = 7 - padding;
@@ -360,8 +360,6 @@
                shift++;
        }

-       free(data);
-
        return z;
 }


--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/27004
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id2bb31b4d00bb91d3dcc302910e5d2da95be9a25
Gerrit-Change-Number: 27004
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-MessageType: newchange

Reply via email to