6

Espressif IoT Development Framework | How Not To Code

 3 years ago
source link: https://hownot2code.com/2021/01/31/espressif-iot-development-framework/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Espressif IoT Development Framework

|| operator instead of &&

esp_err_t essl_sdio_init(void *arg, uint32_t wait_ms)
{
  ....
  // Set block sizes for functions 1 to given value (default value = 512).
  if (ctx->block_size > 0 || ctx->block_size <= 2048) {
    bs = ctx->block_size;
  } else {
    bs = 512;
  }
  ....
}

PVS-Studio warning: V547 Expression is always true. essl_sdio.c 209

One can attribute this bug to typos. In my opinion, by its nature it’s closer to logical errors. I think the reader understands that classification of errors is often quite conditional.

So, what we have here is an always true condition. As a certain variable is always either greater than 0 or less than 2048. Because of this, the size of a block will not be limited to 512.

Here is the correct version of code:

if (ctx->block_size > 0 && ctx->block_size <= 2048) {
  bs = ctx->block_size;
} else {
  bs = 512;
}

Please click here to see more bugs from this project.

Loading...

Related


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK