<p>fixeria has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/22543">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">gsm_7bit_encode_n(): use regular malloc() instead of calloc()<br><br>In general, it's safe not to use talloc API here because those are<br>internal allocations, and there are no 'return' statements between<br>calloc() and free().  However, we don't really need to initialize<br>the heap memory with 0, so let's use the 'normal' malloc().<br><br>Change-Id: I6956cbd83b2999dbcf8e2d210134b0a166c33efb<br>---<br>M src/gsm/gsm_utils.c<br>1 file changed, 3 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/43/22543/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c</span><br><span>index ae77a9d..d51f27e 100644</span><br><span>--- a/src/gsm/gsm_utils.c</span><br><span>+++ b/src/gsm/gsm_utils.c</span><br><span>@@ -329,12 +329,13 @@</span><br><span>   int i = 0, z = 0;</span><br><span>    uint8_t cb, nb;</span><br><span>      int shift = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t *data = calloc(septet_len + 1, sizeof(uint8_t));</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t *data = malloc(septet_len + 1);</span><br><span> </span><br><span>  if (padding) {</span><br><span>               shift = 7 - padding;</span><br><span>                 /* the first zero is needed for padding */</span><br><span>           memcpy(data + 1, rdata, septet_len);</span><br><span style="color: hsl(120, 100%, 40%);">+          data[0] = 0x00;</span><br><span>              septet_len++;</span><br><span>        } else</span><br><span>               memcpy(data, rdata, septet_len);</span><br><span>@@ -382,7 +383,7 @@</span><br><span>       size_t max_septets = n * 8 / 7;</span><br><span> </span><br><span>  /* prepare for the worst case, every character expanding to two bytes */</span><br><span style="color: hsl(0, 100%, 40%);">-        uint8_t *rdata = calloc(strlen(data) * 2, sizeof(uint8_t));</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t *rdata = malloc(strlen(data) * 2);</span><br><span>   y = gsm_septet_encode(rdata, data);</span><br><span> </span><br><span>      if (y > max_septets) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/22543">change 22543</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/22543"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I6956cbd83b2999dbcf8e2d210134b0a166c33efb </div>
<div style="display:none"> Gerrit-Change-Number: 22543 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>