2022-03-20

Parasoft / Misra C++ 2008 : Expression of 'signed' type should not be cast to 'unsigned' type

I am coding in C++14. The company requires all code to pass Parasoft / Misra C++ 2008 checks.

I receive a string which ends in a digit from 1 to N and I need to convert it to uint8_t and subtract 1 to use it as an array index.

// NumberString is guaranteed to contain a single digit as a std::string
const uint8_t Number = static_cast<uint8_t>(std::stoi(NumberString) - 1);

causes Parasoft to report

Expression of 'signed' type should not be cast to 'unsigned' type

I have tried many ways to rewrite it, but to no avail. How can I get rid of that Parasoft message?

I am out of ideas and even considering stuffing an extra (unused) element zer0 at the front of that array. Surely there must be a way to avoid that?



No comments:

Post a Comment