1

Topic: IAR compilation warning in src\ssl.c

Hello,

I got a compilation warning in IAR C/C++ Compiler for ARM 7.70.2.11706 (7.70.2.11706) regarding uninitialized variable in src\ssl.c, version 3.9.8:

Warning[Pe549]: variable "ticketLen" is used before its value is set C:\projects\mcu-sdk-2.0\middleware\wolfssl\src\ssl.c 7637

static int GetDeepCopySession(WOLFSSL* ssl, WOLFSSL_SESSION* copyFrom)
{
    WOLFSSL_SESSION* copyInto = &ssl->session;
    void* tmpBuff             = NULL;
    int ticketLen;
    int doDynamicCopy         = 0;
    int ret                   = SSL_SUCCESS;

[b]    (void)ticketLen;[/b]
    (void)doDynamicCopy;
    (void)tmpBuff;
...

Although this should be pretty harmless, could it be fixed? The code in 3.9.10 looks the same.

Thanks,
Stana

Share

2 (edited by Kaleb J. Himes 2016-10-26 08:26:26)

Re: IAR compilation warning in src\ssl.c

Hi sp,

This is indeed a strange warning. The reason we cast to void is there exists paths such that ticketLen may not be used. In that event we do not wish a compiler to throw a build time error/warning for "unused variable". By casting to void after declaration most C compilers see that it gets used at least once and will not complain. We have never seen a compiler throw a "used before set" on the void cast, that is new. Thank you for sharing.

You can resolve by setting it equal to 0, same as for "doDynamicCopy" variable.


Regards,

Kaleb

Re: IAR compilation warning in src\ssl.c

Hi sp,

I have opened a pull request to address this build time warning:

https://github.com/wolfSSL/wolfssl/pull … 55c9d378f4


Kind Regards,

4

Re: IAR compilation warning in src\ssl.c

Hi Kaleb,

Thank you. I will assign 0 until the fixed version is released.

By the way I removed our project suppressed warnings and got this in Keil MDK:

*** Using Compiler 'V5.06 update 2 (build 183)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'

src\internal.c(13889): warning:  #1293-D: assignment in condition
              if (!(ret = wc_InitSha256(sha256))
src\internal.c(13890): warning:  #1293-D: assignment in condition
              &&  !(ret = wc_Sha256Update(sha256, ssl->arrays->clientRandom,
src\internal.c(13892): warning:  #1293-D: assignment in condition
              &&  !(ret = wc_Sha256Update(sha256, ssl->arrays->serverRandom,
src\internal.c(13894): warning:  #1293-D: assignment in condition
              &&  !(ret = wc_Sha256Update(sha256, messageVerify, verifySz))) {

And this in IAR:

Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\asn.c 546
Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\asn.c 563 
Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\asn.c 3381
Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\asn.c 3394 
Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\asn.c 3999 
Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\asn.c 4035
Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\asn.c 4533 
Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\asn.c 4534 

Warning[Pa089]: enumerated type mixed with another enumerated type wolfcrypt\src\hash.c 110 

Warning[Pa089]: enumerated type mixed with another enumerated type src\keys.c 2842 
Warning[Pa089]: enumerated type mixed with another enumerated type src\keys.c 2843 
Warning[Pa089]: enumerated type mixed with another enumerated type src\keys.c 2844 
Warning[Pa089]: enumerated type mixed with another enumerated type src\keys.c 2896 
Warning[Pa089]: enumerated type mixed with another enumerated type src\keys.c 2901 
Warning[Pa089]: enumerated type mixed with another enumerated type src\keys.c 2955 
Warning[Pa089]: enumerated type mixed with another enumerated type src\keys.c 2956 

Using wolfssl-3.9.8-commercial.

Best regards,
Stana

Share

Re: IAR compilation warning in src\ssl.c

Hi Stana,


1.

Warnings of this nature:

src\internal.c(13894): warning:  #1293-D: assignment in condition
              &&  !(ret = wc_Sha256Update(sha256, messageVerify, verifySz))) {

are thown by SOME but not all C compilers. Depending on the compiler this warning basically saying:

"Hey you have an if condition like this:

 if (x = 1) { do something; } 

"Did you really mean to do this?:

if (x == 1) { do something; }

It's a friendly reminder that you may have made a mistake but it does not mean it is incorrect. This is something we have evaluated internally in the past and we decided at that time it is not something we feel is necessary to change since all compilers (that we know of) that do throw this warning also provide an option to disable the warning.

That being said we have not discussed it in some time so I will voice your concern in our next meeting and see if the team still feels the same.



2. Could you send me the full list of enumerated type mixed with another type that you are seeing (kaleb@wolfssl.com) or is what you included the full list? We will evaluate these and see if there is any potential for undefined or dangerous behavior. Once evaluated I will post an update on this thread.


Thanks,

Kaleb