mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-05 02:05:23 +00:00
Add a Coccinelle script that adds an 'U' to values assigned to unsigned variables, according ot MISRA-C rule 7.2. Add a 'report' mode to the script that can be used by developer/CI and a 'patch' mode that should do the heavy lifting. Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
46 lines
1019 B
Plaintext
46 lines
1019 B
Plaintext
/// Find assignments to unsigned variables and add an 'U' to the value
|
|
// Copyright: (C) 2018 Intel Corporation
|
|
// Copyright: (C) 2018 Himanshu Jha
|
|
// Copyright: (C) 2018 Julia Lawall, Inria/LIP6
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// Confidence: High
|
|
|
|
virtual patch
|
|
virtual report
|
|
|
|
@r_unsigned@
|
|
typedef uint8_t, uint16_t, uint32_t, uint64_t, u8_t, u16_t, u32_t, u64_t;
|
|
{unsigned char, unsigned short, unsigned int, uint8_t, uint16_t, uint32_t, uint64_t, u8_t, u16_t, u32_t, u64_t} v;
|
|
constant C;
|
|
position p;
|
|
@@
|
|
|
|
v = C@p
|
|
|
|
@script:python r_rewrite@
|
|
C << r_unsigned.C;
|
|
z;
|
|
@@
|
|
|
|
if C.isdigit() != True:
|
|
cocci.include_match(False)
|
|
|
|
coccinelle.z = C + "U"
|
|
|
|
@r_subst depends on patch@
|
|
{unsigned char, unsigned short, unsigned int, uint8_t, uint16_t, uint32_t, uint64_t, u8_t, u16_t, u32_t, u64_t} r_unsigned.v;
|
|
constant r_unsigned.C;
|
|
identifier r_rewrite.z;
|
|
@@
|
|
|
|
v =
|
|
- C
|
|
+ z
|
|
|
|
@script: python depends on report@
|
|
p << r_unsigned.p;
|
|
@@
|
|
|
|
msg="WARNING: Unsigned 'U' suffix missing"
|
|
coccilib.report.print_report(p[0], msg)
|