From 3c1ae779628964735bf18b6c70f317825a8d470f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 23 Sep 2021 10:44:38 +0200 Subject: [PATCH] Fixed #10499 (FP: misra-c2012-10.4) --- addons/misra.py | 7 +++++++ addons/test/misra/misra-test.c | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index ae5855dbc..bdfde1ae0 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -459,6 +459,13 @@ def getEssentialTypeCategory(expr): if typeToken.valueType.sign: return typeToken.valueType.sign typeToken = typeToken.next + + # See Appendix D, section D.6, Character constants + if expr.str[0] == "'" and expr.str[-1] == "'": + if len(expr.str) == 3 or (len(expr.str) == 4 and expr.str[1] == '\\'): + return 'char' + return expr.valueType.sign + if expr.valueType: return expr.valueType.sign return None diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index d5dbf9a62..4f86d8231 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -669,13 +669,13 @@ static void misra_10_2(void) { float f32a = 0.0; char res; - res = '0' + u8a; // 10.4 + res = '0' + u8a; // Convert u8a to digit res = s8a + '0'; res = cha - '0'; res = '0' - s8a; res = cha + ':'; // 10.2 - res = s16a - 'a'; // 10.2 10.3 + res = s16a - 'a'; // 10.2 10.3 10.4 res = '0' + f32a; // 10.2 10.4 } @@ -699,6 +699,12 @@ static void misra_10_4(u32 x, s32 y) { z = x + y; //10.4 z = (a == misra_10_4_A3) ? x : y; //10.4 z = (a == misra_10_4_A3) ? y : y; // no-warning + + // #10499 + const char buf[10] = {0}; + if ('0' == buf[x]) // no-warning + { + } } static void misra_10_5(uint16_t x) {