MQTT-TLS lib: variable may be used uninitialized warning

Hi there,

I see the following warning when compiling MQTT-TLS:

In member function 'MQTT::handShakeTls()':

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)

(... 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


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.


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.