From 846db1b3c3a224313f0459485d8e9cc7cb8cfd4b Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sat, 30 Jan 2021 01:22:03 +0100 Subject: [PATCH] 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 --- src/gsm/gsm_utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c index f8bb58eb0..3b0ec6a8b 100644 --- a/src/gsm/gsm_utils.c +++ b/src/gsm/gsm_utils.c @@ -325,12 +325,13 @@ int gsm_septet_pack(uint8_t *result, const uint8_t *rdata, size_t septet_len, ui 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 @@ int gsm_7bit_encode_n(uint8_t *result, size_t n, const char *data, int *octets) 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) {