Skip to content

Commit 3c1ae77

Browse files
committed
Fixed #10499 (FP: misra-c2012-10.4)
1 parent 2e682b1 commit 3c1ae77

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

addons/misra.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ def getEssentialTypeCategory(expr):
459459
if typeToken.valueType.sign:
460460
return typeToken.valueType.sign
461461
typeToken = typeToken.next
462+
463+
# See Appendix D, section D.6, Character constants
464+
if expr.str[0] == "'" and expr.str[-1] == "'":
465+
if len(expr.str) == 3 or (len(expr.str) == 4 and expr.str[1] == '\\'):
466+
return 'char'
467+
return expr.valueType.sign
468+
462469
if expr.valueType:
463470
return expr.valueType.sign
464471
return None

addons/test/misra/misra-test.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,13 @@ static void misra_10_2(void) {
669669
float f32a = 0.0;
670670
char res;
671671

672-
res = '0' + u8a; // 10.4
672+
res = '0' + u8a; // Convert u8a to digit
673673
res = s8a + '0';
674674
res = cha - '0';
675675
res = '0' - s8a;
676676
res = cha + ':'; // 10.2
677677

678-
res = s16a - 'a'; // 10.2 10.3
678+
res = s16a - 'a'; // 10.2 10.3 10.4
679679
res = '0' + f32a; // 10.2 10.4
680680
}
681681

@@ -699,6 +699,12 @@ static void misra_10_4(u32 x, s32 y) {
699699
z = x + y; //10.4
700700
z = (a == misra_10_4_A3) ? x : y; //10.4
701701
z = (a == misra_10_4_A3) ? y : y; // no-warning
702+
703+
// #10499
704+
const char buf[10] = {0};
705+
if ('0' == buf[x]) // no-warning
706+
{
707+
}
702708
}
703709

704710
static void misra_10_5(uint16_t x) {

0 commit comments

Comments
 (0)