<p>neels has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/15218">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">osmo_tdef_get(): allow passing -1 as default timeout<br><br>The intention of osmo_tdef_get()'s val_if_not_present argument was to return a<br>default timeout, or to optionally abort the program for missing timer<br>definitions if the default timeout is < 0. This was the case in the original<br>implementation of this API in osmo-bsc, but in the migration to libosmocore,<br>the argument was by accident changed to an unsigned type. In consequence, the<br>assertion in the implementation that was intended to abort the program seemed<br>bogus to coverity, and was fixed by removal in<br>I7a544d2d43b83135def296674f777e48fe5fd80a -- the wrong direction, as is obvious<br>from the API doc for osmo_tdef_get().<br><br>Note that osmo-bsc master passes -1 in various places and expects the<br>program-abort behavior that was missing from the libosmocore implementation.<br><br>Change the val_if_not_present argument to a signed type, and revert removal of<br>the assertion, so that passing -1 has the effect described in the API doc:<br>program abort on missing timer definition.<br><br>This bug was not detected because it is hard to write tests that expect a<br>program abort to happen, hence no tests for this API feature exist.<br><br>Change-Id: Ie61c3c85069916336e6dbd91a2c16f7634816417<br>---<br>M TODO-RELEASE<br>M include/osmocom/core/tdef.h<br>M src/tdef.c<br>3 files changed, 4 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/18/15218/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/TODO-RELEASE b/TODO-RELEASE</span><br><span>index 8ccfa49..665ecf7 100644</span><br><span>--- a/TODO-RELEASE</span><br><span>+++ b/TODO-RELEASE</span><br><span>@@ -7,3 +7,4 @@</span><br><span> # If any interfaces have been added since the last public release: c:r:a + 1.</span><br><span> # If any interfaces have been removed or changed since the last public release: c:r:0.</span><br><span> #library      what                    description / commit summary line</span><br><span style="color: hsl(120, 100%, 40%);">+core         osmo_tdef_get()         change val_if_not_present arg from unsigned long to long to allow passing -1</span><br><span>diff --git a/include/osmocom/core/tdef.h b/include/osmocom/core/tdef.h</span><br><span>index c8d9053..566f5dd 100644</span><br><span>--- a/include/osmocom/core/tdef.h</span><br><span>+++ b/include/osmocom/core/tdef.h</span><br><span>@@ -95,7 +95,7 @@</span><br><span> </span><br><span> void osmo_tdefs_reset(struct osmo_tdef *tdefs);</span><br><span> unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit,</span><br><span style="color: hsl(0, 100%, 40%);">-                          unsigned long val_if_not_present);</span><br><span style="color: hsl(120, 100%, 40%);">+                            long val_if_not_present);</span><br><span> struct osmo_tdef *osmo_tdef_get_entry(struct osmo_tdef *tdefs, int T);</span><br><span> </span><br><span> /*! Using osmo_tdef for osmo_fsm_inst: array entry for a mapping of state numbers to timeout definitions.</span><br><span>diff --git a/src/tdef.c b/src/tdef.c</span><br><span>index 3cfb17c..40a9900 100644</span><br><span>--- a/src/tdef.c</span><br><span>+++ b/src/tdef.c</span><br><span>@@ -183,10 +183,11 @@</span><br><span>  * \param[in] val_if_not_present  Fallback value to return if no timeout is defined.</span><br><span>  * \return Timeout value in the unit given by as_unit, rounded up if necessary, or val_if_not_present.</span><br><span>  */</span><br><span style="color: hsl(0, 100%, 40%);">-unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit, unsigned long val_if_not_present)</span><br><span style="color: hsl(120, 100%, 40%);">+unsigned long osmo_tdef_get(const struct osmo_tdef *tdefs, int T, enum osmo_tdef_unit as_unit, long val_if_not_present)</span><br><span> {</span><br><span>         const struct osmo_tdef *t = osmo_tdef_get_entry((struct osmo_tdef*)tdefs, T);</span><br><span>        if (!t) {</span><br><span style="color: hsl(120, 100%, 40%);">+             OSMO_ASSERT(val_if_not_present >= 0);</span><br><span>             return val_if_not_present;</span><br><span>   }</span><br><span>    return osmo_tdef_round(t->val, t->unit, as_unit);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/15218">change 15218</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/+/15218"/><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: Ie61c3c85069916336e6dbd91a2c16f7634816417 </div>
<div style="display:none"> Gerrit-Change-Number: 15218 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>