Fix #10652: FP: misra-c2012-10.4 (char)'1' != (char) (#5556)

This commit is contained in:
Swasti Shrivastava 2023-10-16 22:23:51 +05:30 committed by GitHub
parent 3811d01498
commit ad4e688ff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -495,6 +495,13 @@ def getEssentialTypeCategory(expr):
return 'char'
return expr.valueType.sign
if (expr.isCast and expr.str == "("):
castTok = expr.next
while castTok.isName or castTok.str == "*":
if castTok.str == 'char' and not castTok.isSigned and not castTok.isUnsigned:
return 'char'
castTok = castTok.next
if expr.valueType:
return expr.valueType.sign
return None

View File

@ -724,6 +724,12 @@ static void misra_10_4(u32 x, s32 y) {
if ('\0' == cmd.buf[0]) //no-warning
{
}
// #10652
char c;
if ((char)'1' == c) {} // no warning
if ((unsigned char)'1' == c) {} //10.4
if ((signed char)'1' == c) {} //10.4
}
static void misra_10_5(uint16_t x) {