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
changes/43/22543/2
Vadim Yanitskiy 2 years ago
parent 4c44d46308
commit 846db1b3c3
  1. 5
      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) {

Loading…
Cancel
Save