MQTT-TLS lib: variable may be used uninitialized warning

Hi there,

I see the following warning when compiling MQTT-TLS:

/Users/me/bestPrjEver/lib/MQTT-TLS/src/MQTT-TLS.cpp: 
In member function 'MQTT::handShakeTls()':

/Users/me/bestPrjEver/lib/MQTT-TLS/src/MQTT-TLS.cpp:727:45: 
warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
  727 |   } while (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE);

Here’s the function where this is happening:

int MQTT::handShakeTls() {
  int ret;
  debug_tls("hand shake start\n");
  do {
      while (ssl.state != MBEDTLS_SSL_HANDSHAKE_OVER) {
          ret = mbedtls_ssl_handshake_client_step(&ssl);
          if (ret != 0)
              break;
      }
  } while (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE);

(... there is more code, not shown for convenience ...)

Now the question:
How bad is it on a Particle device when code potentially uses an uninitialized variable value?

I can file a PR in the lib, but I want to know if this is something to worry about, or safe to ignore.
FYI: @hirotakaster

Thanks!

The only case where it could be uninitialized is if ssl.state == MBEDTLS_SSL_HANDSHAKE_OVER on entry. I’m not familiar with this code, but given the message “hand shake start” I’d guess that it should never be over on entry. It wouldn’t hurt to initialize it, though, to get rid of the warning and to be sure.

2 Likes

Hi,
do - (exec statement) - while(conditions check) , do-while statements order are executed following,
(exec statement)
(conditions check)

And TLS state is before handshake on this function( ssl.state != MBEDTLS_SSL_HANDSHAKE_OVER ) , so mbedtls_ssl_handshake_client_step function is definitely executed, then “ret” variable is set to some value.

As a rickkas7 said, I think it is okay to initialize ret value to remove the warning.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.