<p><a href="https://gerrit.osmocom.org/c/libosmocore/+/26308">View Change</a></p><p>2 comments:</p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0;"><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/26308/1/src/bitvec.c">File src/bitvec.c:</a></p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.osmocom.org/c/libosmocore/+/26308/1/src/bitvec.c@485">Patch Set #1, Line 485:</a> <code style="font-family:monospace,monospace">      if (len && bytenum_from_bitnum(*read_index + len - 1) >= bv->data_len) {</code></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">why this -1?</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">Because we check presence of the *last* bit here. If let's say len=32, then the last bit you're interested in the 31th bit because we count from 0. Without that -1 parsing e.g. 32 our of 32 bits in the vector won't work.</p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">  // read_index=0, len=32, bv->data_len=4<br>  if (bytenum_from_bitnum(0 + 32 - 1) >= 4) {  ... }<br>  if (bytenum_from_bitnum(31) >= 4) {  ... }<br>  if (31 / 8 >= 4) {  ... }<br>  if (3 >= 4) {  ... } // false</pre><p style="white-space: pre-wrap; word-wrap: break-word;">This is also why below we do:</p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">  ((uint64_t)1 << (len - i - 1))</pre></li><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.osmocom.org/c/libosmocore/+/26308/1/src/bitvec.c@494">Patch Set #1, Line 494:</a> <code style="font-family:monospace,monospace">            int bit = bitvec_get_bit_pos((const struct bitvec *)bv, bv->cur_bit);</code></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">I'd rather still keep the error checking here.</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">Why not, if we can check once and then avoid additional 'if' statements in a loop?</p><p style="white-space: pre-wrap; word-wrap: break-word;">Moreover, the idea is to catch the error before entering the loop and doing:</p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">  ((uint64_t)1 << (len - i - 1))</pre><p style="white-space: pre-wrap; word-wrap: break-word;">Otherwise it takes several iterations to realize that we're reading out of bounds.</p></li></ul></li></ul><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/26308">change 26308</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/+/26308"/><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: I4deeabba7ebb720cdbe7c85b37bc011d05bdfa65 </div>
<div style="display:none"> Gerrit-Change-Number: 26308 </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-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-CC: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Comment-Date: Wed, 17 Nov 2021 14:58:24 +0000 </div>
<div style="display:none"> Gerrit-HasComments: Yes </div>
<div style="display:none"> Gerrit-Has-Labels: No </div>
<div style="display:none"> Comment-In-Reply-To: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: comment </div>