
BUG OF THE MONTH | || 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.