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
This commit is contained in:
Vadim Yanitskiy 2021-01-30 01:22:03 +01:00
parent 4c44d46308
commit 846db1b3c3
1 changed files with 3 additions and 2 deletions

View File

@ -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; int i = 0, z = 0;
uint8_t cb, nb; uint8_t cb, nb;
int shift = 0; int shift = 0;
uint8_t *data = calloc(septet_len + 1, sizeof(uint8_t)); uint8_t *data = malloc(septet_len + 1);
if (padding) { if (padding) {
shift = 7 - padding; shift = 7 - padding;
/* the first zero is needed for padding */ /* the first zero is needed for padding */
memcpy(data + 1, rdata, septet_len); memcpy(data + 1, rdata, septet_len);
data[0] = 0x00;
septet_len++; septet_len++;
} else } else
memcpy(data, rdata, septet_len); 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; size_t max_septets = n * 8 / 7;
/* prepare for the worst case, every character expanding to two bytes */ /* 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); y = gsm_septet_encode(rdata, data);
if (y > max_septets) { if (y > max_septets) {