<p>Harald Welte has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/12641">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">WIP: Attempt to avoid bogus gcc-8.2 array-bounds warning/error<br><br>gcc-8.2 is printing the following warning, which is an error<br>when used -Werror like our --enable-werror:<br><br>In file included from gprs_bssgp.c:34:<br>In function ‘tl16v_put’,<br>    inlined from ‘tvlv_put.part.3’ at ../../include/osmocom/gsm/tlv.h:156:9,<br>    inlined from ‘tvlv_put’ at ../../include/osmocom/gsm/tlv.h:147:24,<br>    inlined from ‘msgb_tvlv_push’ at ../../include/osmocom/gsm/tlv.h:386:2,<br>    inlined from ‘bssgp_tx_dl_ud’ at gprs_bssgp.c:1162:4:<br>../../include/osmocom/gsm/tlv.h:131:2: error: ‘memcpy’ forming offset [11, 130] is out of the bounds [0, 10] of object ‘mi’ with type ‘uint8_t[10]’ {aka ‘unsigned char[10]’} [-Werror=array-bounds]<br>  memcpy(buf, val, len);<br><br>Where "130" sems to be the maximum value of uint8_t, shifted right one +<br>2.  But even if we use strnlen() with "16" as maximum upper bound, gcc<br>still believes there's a way that the return value of gsm48_generate_mid_from_imsi()<br>could be 130.  In fact, even when adding OSMO_ASSERTs inside<br>gsm48_generate_mid(), gcc insists there is a problem :(<br><br>Change-Id: Ic8488bc7f77dc9182e372741b88f0f06100dddc9<br>---<br>M src/gsm/gsm48.c<br>1 file changed, 4 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/41/12641/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c</span><br><span>index 795e98b..7e2564a 100644</span><br><span>--- a/src/gsm/gsm48.c</span><br><span>+++ b/src/gsm/gsm48.c</span><br><span>@@ -644,13 +644,15 @@</span><br><span>  *  \returns number of bytes used in \a buf */</span><br><span> uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-   uint8_t length = strnlen(id, 255), i, off = 0, odd = (length & 1) == 1;</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t length = strnlen(id, 16), i, off = 0, odd = (length & 1) == 1;</span><br><span style="color: hsl(120, 100%, 40%);">+    /* maximum length == 16 */</span><br><span> </span><br><span>       buf[0] = GSM48_IE_MOBILE_ID;</span><br><span>         buf[2] = osmo_char2bcd(id[0]) << 4 | (mi_type & GSM_MI_TYPE_MASK) | (odd << 3);</span><br><span> </span><br><span>  /* if the length is even we will fill half of the last octet */</span><br><span>      buf[1] = (length + (odd ? 1 : 2)) >> 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* buf[1] maximum = 18/2 = 9 */</span><br><span> </span><br><span>  for (i = 1; i < buf[1]; ++i) {</span><br><span>            uint8_t upper, lower = osmo_char2bcd(id[++off]);</span><br><span>@@ -662,6 +664,7 @@</span><br><span>               buf[2 + i] = (upper << 4) | lower;</span><br><span>     }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* maximum return value: 2 + 9 = 11 */</span><br><span>       return 2 + buf[1];</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/12641">change 12641</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/12641"/><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-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ic8488bc7f77dc9182e372741b88f0f06100dddc9 </div>
<div style="display:none"> Gerrit-Change-Number: 12641 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Harald Welte <laforge@gnumonks.org> </div>