laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/22543 )
Change subject: gsm_7bit_encode_n(): use regular malloc() instead of calloc() ......................................................................
gsm_7bit_encode_n(): use regular malloc() instead of calloc()
In general, it's safe not to use talloc API here because those are internal allocations, and there are no 'return' statements between calloc() and free(). However, we don't really need to initialize the heap memory with 0, so let's use the 'normal' malloc().
Change-Id: I6956cbd83b2999dbcf8e2d210134b0a166c33efb --- M src/gsm/gsm_utils.c 1 file changed, 3 insertions(+), 2 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c index f8bb58e..3b0ec6a 100644 --- a/src/gsm/gsm_utils.c +++ b/src/gsm/gsm_utils.c @@ -325,12 +325,13 @@ int i = 0, z = 0; uint8_t cb, nb; int shift = 0; - uint8_t *data = calloc(septet_len + 1, sizeof(uint8_t)); + uint8_t *data = malloc(septet_len + 1);
if (padding) { shift = 7 - padding; /* the first zero is needed for padding */ memcpy(data + 1, rdata, septet_len); + data[0] = 0x00; septet_len++; } else memcpy(data, rdata, septet_len); @@ -384,7 +385,7 @@ size_t max_septets = n * 8 / 7;
/* prepare for the worst case, every character expanding to two bytes */ - uint8_t *rdata = calloc(strlen(data) * 2, sizeof(uint8_t)); + uint8_t *rdata = malloc(strlen(data) * 2); y = gsm_septet_encode(rdata, data);
if (y > max_septets) {