I am compiling the below sample code but getting some warning messages. How to resolve these warning messages?
#include <iostream>
#include <cstdio>
#include <cstdint>
int main()
{
struct stRecord
{
uint8_t SType;
uint8_t TypeNo;
uint8_t Length[2];
uint8_t Address[8];
};
uint8_t payload_size = 37;
size_t fw_remaining_size = 80;
if ((payload_size + 1U) * 2 > fw_remaining_size - sizeof(stRecord))
{
}
return 0;
}
if ((payload_size + 1U) * 2 > fw_remaining_size - sizeof(stRecord))
At the above line, getting below warning messages:
C26451: Arithmetic overflow: Using operator '*' on a 4 byte value and then casting the result to a 8 byte value.
Cast the value to the wider type before calling operator '*' to avoid overflow (io.2).
C26451: Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value.
Cast the value to the wider type before calling operator '+' to avoid overflow (io.2).
I am trying to avoid the (static_cast<size_t>(payload_size)