aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2021-01-30 01:22:03 +0100
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2022-01-29 01:02:32 +0600
commit846db1b3c3a224313f0459485d8e9cc7cb8cfd4b (patch)
tree0e8452a2a7f0cf5fabae215f006f7ba99ffd31d6
parentlogging: log to stderr when logging is not initialized (diff)
downloadlibosmocore-846db1b3c3a224313f0459485d8e9cc7cb8cfd4b.tar.xz
libosmocore-846db1b3c3a224313f0459485d8e9cc7cb8cfd4b.zip
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
-rw-r--r--src/gsm/gsm_utils.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index f8bb58eb..3b0ec6a8 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) {