<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — [SOLVED] Warning when compiling wolfssl with WOLFSSL_KEY_GEN set]]></title>
		<link>https://www.wolfssl.com/forums/topic739-solved-warning-when-compiling-wolfssl-with-wolfsslkeygen-set.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic739.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in [SOLVED] Warning when compiling wolfssl with WOLFSSL_KEY_GEN set.]]></description>
		<lastBuildDate>Mon, 23 Nov 2015 16:33:53 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: [SOLVED] Warning when compiling wolfssl with WOLFSSL_KEY_GEN set]]></title>
			<link>https://www.wolfssl.com/forums/post2344.html#p2344</link>
			<description><![CDATA[<p>Hi Steve,</p><p>No problem. It was a good proof for us to work through on our end as well. Thank you for your question.</p><br /><p>Best Regards,</p><p>Kaleb</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Mon, 23 Nov 2015 16:33:53 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2344.html#p2344</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Warning when compiling wolfssl with WOLFSSL_KEY_GEN set]]></title>
			<link>https://www.wolfssl.com/forums/post2331.html#p2331</link>
			<description><![CDATA[<p>Thanks Kaleb - I had assumed it was probably a false warning because management of mp_int is handled by the application.&nbsp; I definitely appreciate your research and work on this!</p><p>Steve</p>]]></description>
			<author><![CDATA[null@example.com (gawiz)]]></author>
			<pubDate>Wed, 18 Nov 2015 21:15:35 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2331.html#p2331</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Warning when compiling wolfssl with WOLFSSL_KEY_GEN set]]></title>
			<link>https://www.wolfssl.com/forums/post2330.html#p2330</link>
			<description><![CDATA[<p>Hi gawiz,</p><p>Our mp_int structure is laid out as seen below. You can view this structure in &lt;wolfssl_root&gt;/wolfssl/wolfcrypt/integer.h<br /></p><div class="codebox"><pre><code> /* the infamous mp_int structure */                                             
 typedef struct  {                                                               
     int used, alloc, sign;                                                      
     mp_digit *dp;                                                               
 } mp_int;</code></pre></div><p>The Visual Studio compiler is complaining that the mp_digit pointer (dp) is potentially not initialized. By assigning 0x0 to this pointer at the time of declaration you can silence this warning. I would add a comment to note this is only to silence an MSVS static analysis warning.</p><p>I did the following in integer.c:<br /></p><div class="codebox"><pre><code> static int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d)          
 {                                                                               
   mp_int  q;
   q.dp = NULL;

... rest of the function here ...
 }</code></pre></div><p>Evaluating this thoroughly we have proven it can never be &quot;uninitialized&quot; by the time the assignment takes place. This is a false positive from MSVS.</p><p>Proof follows:<br /></p><div class="codebox"><pre><code>if c IS NOT NULL the mp_init_size will initialize q and malloc q.dp
The first time q is used if c IS NULL (outside the first if block) is in the for loop.
The value of c can not change between if block and for loop.
the value of c can not change within the for loop
before q is used in the for loop (the line MSVS complains about) c is again evaluated
if c IS NULL q will not be used / cannot be used &quot;uninitialized&quot;
we can conclude the following:

q is used iff c != NULL.
if c != NULL q is initialized in the if block (line 4096 below)
c cannot become NULL between if block and for loop,
therefore q.dp can never be used uninitialized.

4096   if (c != NULL) {                                                             
4097       if ((res = mp_init_size(&amp;q, a-&gt;used)) != MP_OKAY) {                       
4098         return res;                                                             
4099       }                                                                         
4100                                                                                 
4101       q.used = a-&gt;used;                                                         
4102       q.sign = a-&gt;sign;                                                         
4103   }                                                                             
4104                                                                                 
4105   w = 0;                                                                        
4106   for (ix = a-&gt;used - 1; ix &gt;= 0; ix--) {                                       
4107      w = (w &lt;&lt; ((mp_word)DIGIT_BIT)) | ((mp_word)a-&gt;dp[ix]);                    
4108                                                                                 
4109      if (w &gt;= b) {                                                              
4110         t = (mp_digit)(w / b);                                                  
4111         w -= ((mp_word)t) * ((mp_word)b);                                       
4112       } else {                                                                  
4113         t = 0;                                                                  
4114       }                                                                         
4115       if (c != NULL)                                                            
4116         q.dp[ix] = (mp_digit)t;                                                 
4117   }</code></pre></div><p>Best regards,</p><p>Kaleb</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Wed, 18 Nov 2015 18:35:33 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2330.html#p2330</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Warning when compiling wolfssl with WOLFSSL_KEY_GEN set]]></title>
			<link>https://www.wolfssl.com/forums/post2329.html#p2329</link>
			<description><![CDATA[<p>Hi gawiz,</p><p>I added the configure option WOLFSSL_KEY_GEN&nbsp; and I was able to reproduce your warning. I will have a suggestion shortly.</p><br /><p>Regards,</p><p>Kaleb</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Wed, 18 Nov 2015 18:12:46 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2329.html#p2329</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Warning when compiling wolfssl with WOLFSSL_KEY_GEN set]]></title>
			<link>https://www.wolfssl.com/forums/post2326.html#p2326</link>
			<description><![CDATA[<p>(Non-helpful response removed by kaleb)</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Wed, 18 Nov 2015 17:53:25 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2326.html#p2326</guid>
		</item>
		<item>
			<title><![CDATA[[SOLVED] Warning when compiling wolfssl with WOLFSSL_KEY_GEN set]]></title>
			<link>https://www.wolfssl.com/forums/post2309.html#p2309</link>
			<description><![CDATA[<p>I get the following warning in Visual Studio when compiling WolfSSL to a .dll AND I have WOLFSSL_KEY_GEN set in my preprocessor directives.</p><div class="codebox"><pre><code>c:\security\wolfssl-3.7.0\wolfcrypt\src\integer.c(4115): warning C4701: potentially uninitialized local variable &#039;q&#039; used</code></pre></div><p>I&#039;m just guessing that this is because of the way that the mp_digit struct behaves - sort of taking things like validity of a number into its own hands.&nbsp; But yet I have that nagging feeling that I don&#039;t like to have warnings in my build.</p><p>Any thoughts on this?</p>]]></description>
			<author><![CDATA[null@example.com (gawiz)]]></author>
			<pubDate>Fri, 13 Nov 2015 23:46:23 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post2309.html#p2309</guid>
		</item>
	</channel>
</rss>
