Skip to content

Commit 26cebf4

Browse files
Fix #14022: MISRA 7.3 false negative on hexadecimal literal (danmar#7676)
1 parent 01693ba commit 26cebf4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

addons/misra.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,9 @@ def misra_7_2(self, data):
20742074
self.reportError(token, 7, 2)
20752075

20762076
def misra_7_3(self, rawTokens):
2077-
compiled = re.compile(r'^[0-9.]+[Uu]*l+[Uu]*$')
2077+
# Match decimal digits, hex digits, decimal point, and e/E p/P floating
2078+
# point constant exponent separators.
2079+
compiled = re.compile(r'^(0[xX])?[0-9a-fA-FpP.]+[Uu]*l+[Uu]*$')
20782080
for tok in rawTokens:
20792081
if compiled.match(tok.str):
20802082
self.reportError(tok, 7, 3)

addons/test/misra/misra-test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ struct misra_7_3_s
302302
{
303303
uint32_t ul_clka;
304304
uint32_t test123l;
305+
float t = 6.02E23l; // 7.3
306+
float t1 = 6.02E23L;
307+
float u = 0xa1B2.p12l; // 7.3
308+
float u1 = 0xa1B2.p12L;
309+
float v = 0xa1B2.P12l; // 7.3
310+
float v1 = 0xa1B2.P12L;
311+
float w = 6.02e23l; // 7.3
312+
float w1 = 6.02e23L;
313+
unsigned long x = 0xabcul; // 7.3
314+
unsigned long x1 = 0xabcuL;
315+
unsigned long y = 0xABCUl; // 7.3
316+
unsigned long y1 = 0xABCUL;
317+
unsigned long z = 0XdeadBeEfUl; // 7.3
318+
unsigned long z1 = 0XdeadBeEfUL;
305319
};
306320

307321
static void misra_7_3(void) {

0 commit comments

Comments
 (0)