<p>In <a href="https://github.com/OpenSIPS/opensips/pull/836#discussion_r57050628">transformations.c</a>:</p>
<pre style='color:#555'>&gt; +                                if(val-&gt;rs.len == 0) {
&gt; +                                        val-&gt;ri = 0;
&gt; +                                //Try converting to INT
&gt; +                                } else if(str2sint(&amp;val-&gt;rs, &amp;val-&gt;ri)!=0) {
&gt; +                                        //Try converting to Double
&gt; +                                        errno = 0;
&gt; +                                        d = strtod(val-&gt;rs.s, NULL);
&gt; +
&gt; +                                        if(errno != 0) {
&gt; +                                                return -1;
&gt; +                                        }
&gt; +
&gt; +                                        //Use truncation for getting int value. Ensures consistent treatment
&gt; +                                        //trunc(1.5) is 1.0 and trunc(-1.5) is -1.0
&gt; +                                        //mathops gives users more rounding options if they require them
&gt; +                                        val-&gt;ri = trunc(d);
</pre>
<p>The only benefit to adding additional error handling by the use of <code>strtod</code> and <code>trunc</code> is to parse the following values, which <code>str2sint</code> is not able to:</p>

<ul>
<li>signed numbers, prefixed by <code>+</code> or <code>-</code>
</li>
<li>
<code>INF</code> or <code>INFINITY</code>
</li>
<li>
<code>NAN</code> (not a number)</li>
</ul>

<p>Apart from the above negligible benefits, <code>str2sint</code> will successfully parse and truncate all input that's fed to it. Coupled with the fact that we now have to link against <code>lm</code>, I think we should rather:</p>

<ul>
<li>update the function comments on <code>str2sint</code>, so that the truncation / partial parse (just like <code>strtod</code> and friends) is obvious to all devs</li>
<li>avoid further error handling for <code>str2sint</code> and just use its result, after it parsed all it could from the given input</li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly or <a href="https://github.com/OpenSIPS/opensips/pull/836/files/be25fc66e51c7e8358f5156c7d6d1054ef483c5d#r57050628">view it on GitHub</a><img alt="" height="1" src="https://github.com/notifications/beacon/AFOciWoDrIRubu3Fjekcq8qKseemEmbhks5pwD-MgaJpZM4H2UD-.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/OpenSIPS/opensips/pull/836/files/be25fc66e51c7e8358f5156c7d6d1054ef483c5d#r57050628"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>