Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Administrator
Public Cpp Test
Commits
2a291a73
Commit
2a291a73
authored
Oct 23, 2023
by
shengnan hu
Browse files
main
parents
Changes
638
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
367 additions
and
0 deletions
+367
-0
BM-MISRA-C 2012/R.3.2/BM-MISRA-C2012-R.3.2.c
BM-MISRA-C 2012/R.3.2/BM-MISRA-C2012-R.3.2.c
+15
-0
BM-MISRA-C 2012/R.4.1/BM-MISRA-C2012-R.4.1.c
BM-MISRA-C 2012/R.4.1/BM-MISRA-C2012-R.4.1.c
+6
-0
BM-MISRA-C 2012/R.5.1/R.5.1-file1.c
BM-MISRA-C 2012/R.5.1/R.5.1-file1.c
+6
-0
BM-MISRA-C 2012/R.5.1/R.5.1-file2.c
BM-MISRA-C 2012/R.5.1/R.5.1-file2.c
+6
-0
BM-MISRA-C 2012/R.5.1/R.5.1.c
BM-MISRA-C 2012/R.5.1/R.5.1.c
+11
-0
BM-MISRA-C 2012/R.5.2/R.5.2.c
BM-MISRA-C 2012/R.5.2/R.5.2.c
+17
-0
BM-MISRA-C 2012/R.5.3/R.5.3.c
BM-MISRA-C 2012/R.5.3/R.5.3.c
+35
-0
BM-MISRA-C 2012/R.5.4/R.5.4.c
BM-MISRA-C 2012/R.5.4/R.5.4.c
+9
-0
BM-MISRA-C 2012/R.5.5/R.5.5.c
BM-MISRA-C 2012/R.5.5/R.5.5.c
+16
-0
BM-MISRA-C 2012/R.5.6/R.5.6.c
BM-MISRA-C 2012/R.5.6/R.5.6.c
+37
-0
BM-MISRA-C 2012/R.5.7/R.5.7.c
BM-MISRA-C 2012/R.5.7/R.5.7.c
+42
-0
BM-MISRA-C 2012/R.5.8/R.5.8-file1.c
BM-MISRA-C 2012/R.5.8/R.5.8-file1.c
+10
-0
BM-MISRA-C 2012/R.5.8/R.5.8-file2.c
BM-MISRA-C 2012/R.5.8/R.5.8-file2.c
+14
-0
BM-MISRA-C 2012/R.5.9/R.5.9-file1.c
BM-MISRA-C 2012/R.5.9/R.5.9-file1.c
+23
-0
BM-MISRA-C 2012/R.5.9/R.5.9-file2.c
BM-MISRA-C 2012/R.5.9/R.5.9-file2.c
+22
-0
BM-MISRA-C 2012/R.6.1/R.6.1.c
BM-MISRA-C 2012/R.6.1/R.6.1.c
+11
-0
BM-MISRA-C 2012/R.7.1/R.7.1.c
BM-MISRA-C 2012/R.7.1/R.7.1.c
+13
-0
BM-MISRA-C 2012/R.7.3/R.7.3.c
BM-MISRA-C 2012/R.7.3/R.7.3.c
+14
-0
BM-MISRA-C 2012/R.7.4/R.7.4.c
BM-MISRA-C 2012/R.7.4/R.7.4.c
+36
-0
BM-MISRA-C 2012/R.8.1/R.8.1.c
BM-MISRA-C 2012/R.8.1/R.8.1.c
+24
-0
No files found.
BM-MISRA-C 2012/R.3.2/BM-MISRA-C2012-R.3.2.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
extern
bool
b
;
void
f
(
void
)
{
/* Non-compliant */
uint16_t
x
=
0
;
// comment \
if
(
b
)
{
++
x
;
/* This is always executed */
}
}
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.4.1/BM-MISRA-C2012-R.4.1.c
0 → 100644
View file @
2a291a73
const
char
*
s1
=
"
\x41
g"
;
/* Non-compliant */
const
char
*
s2
=
"
\x41
"
"g"
;
/* Compliant - terminated by end of literal */
const
char
*
s3
=
"
\x41\x67
"
;
/* Compliant - terminated by another escape */
int
c1
=
'\
141
t
'
;
/* Non-compliant */
int
c2
=
'\
141
\
t
'
;
/* Compliant - terminated by another escape */
BM-MISRA-C 2012/R.5.1/R.5.1-file1.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
/* Non-compliant */
int32_t
abc
=
0
;
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.1/R.5.1-file2.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
/* Non-compliant */
int32_t
ABC
=
0
;
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.1/R.5.1.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
/* 1234567890123456789012345678901********* Characters */
int32_t
engine_exhaust_gas_temperature_raw
;
int32_t
engine_exhaust_gas_temperature_scaled
;
/* Non-compliant */
/* 1234567890123456789012345678901********* Characters */
int32_t
engine_exhaust_gas_temp_raw
;
int32_t
engine_exhaust_gas_temp_scaled
;
/* Compliant */
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.2/R.5.2.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
/* 1234567890123456789012345678901********* Characters */
extern
int32_t
engine_exhaust_gas_temperature_raw
;
static
int32_t
engine_exhaust_gas_temperature_scaled
;
/* Non-compliant */
void
f
(
void
)
{
/* 1234567890123456789012345678901********* Characters */
int32_t
engine_exhaust_gas_temperature_local
;
/* Compliant */
}
/* 1234567890123456789012345678901********* Characters */
static
int32_t
engine_exhaust_gas_temp_raw
;
static
int32_t
engine_exhaust_gas_temp_scaled
;
/* Compliant */
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.3/R.5.3.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
void
fn1
(
void
)
{
int16_t
i
;
{
int16_t
i
;
/* Non-compliant - hides previous "i" */
i
=
3
;
}
}
struct
astruct
{
int16_t
m
;
};
extern
void
g
(
struct
astruct
*
p
);
int16_t
xyz
=
0
;
void
fn2
(
struct
astruct
xyz
)
/* Non-compliant - outer "xyz" is
* now hidden by parameter name */
{
g
(
&
xyz
);
}
uint16_t
speed
;
void
fn3
(
void
)
{
typedef
float32_t
speed
;
/* Non-compliant - type hides object */
}
// Example code from MISRA C:2012 begin
BM-MISRA-C 2012/R.5.4/R.5.4.c
0 → 100644
View file @
2a291a73
// Example code from MISRA C:2012 begin
/* 1234567890123456789012345678901******* Characters */
#define engine_exhaust_gas_temperature_raw egt_r
#define engine_exhaust_gas_temperature_scaled egt_s
/* Non-compliant */
/* 1234567890123456789012345678901******* Characters */
#define engine_exhaust_gas_temp_raw egt_r
#define engine_exhaust_gas_temp_scaled egt_s
/* Compliant */
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.5/R.5.5.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
/* Non-compliant */
#define Sum1( x, y ) ( ( x ) + ( y ) )
int16_t
Sum1
;
/* Compliant */
#define Sum2( x, y ) ( ( x ) + ( y ) )
int16_t
x
=
Sum2
(
1
,
2
);
/* Non-compliant */
/* 1234567890123456789012345678901********* Characters */
#define low_pressure_turbine_temperature_1 lp_tb_temp_1
static
int32_t
low_pressure_turbine_temperature_2
;
// Example code from MISRA C:2012 begin
BM-MISRA-C 2012/R.5.6/R.5.6.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
void
func
(
void
)
{
{
typedef
unsigned
char
u8_t
;
}
{
typedef
unsigned
char
u8_t
;
/* Non-compliant - reuse */
}
}
typedef
float
mass
;
void
func1
(
void
)
{
float32_t
mass
=
0
.
0
f
;
/* Non-compliant - reuse */
}
typedef
struct
list
{
struct
list
*
next
;
uint16_t
element
;
}
list
;
/* Compliant - exception */
typedef
struct
{
struct
chain
{
struct
chain
*
list
;
uint16_t
element
;
}
s1
;
uint16_t
length
;
}
chain
;
/* Non-compliant - tag "chain" not
* associated with typedef */
// Example code from MISRA C:2012 begin
BM-MISRA-C 2012/R.5.7/R.5.7.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
struct
stag
{
uint16_t
a
;
uint16_t
b
;
};
struct
stag
a1
=
{
0
,
0
};
/* Compliant */
union
stag
a2
=
{
0
,
0
};
/* Non-compliant - Constraint violation in C99 */
struct
deer
{
uint16_t
a
;
uint16_t
b
;
};
void
foo
(
void
)
{
struct
deer
{
uint16_t
a
;
};
/* Non-compliant - tag “deer” reused */
}
typedef
struct
coord
{
uint16_t
x
;
uint16_t
y
;
}
coord
;
/* Compliant by Exception */
struct
elk
{
uint16_t
x
;
};
struct
elk
/* Non-compliant - Constraint violation in C99 */
{
uint32_t
x
;
};
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.8/R.5.8-file1.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
int32_t
count
;
/* “count” has external linkage */
void
foo
(
void
)
/* “foo” has external linkage */
{
int16_t
index
;
/* “index” has no linkage */
}
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.8/R.5.8-file2.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
static
void
foo
(
void
)
/* Non-compliant - "foo" is not unique
* (it is already defined with wxternal
* linkage in file1.c) */
{
int16_t
count
;
/* Non-compliant - "count" has no linkage
* but clashes with an identifier with
* externlinkage */
int32_t
index
;
/* Compliant - "index" has no linkage */
}
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.9/R.5.9-file1.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
static
int32_t
count
;
/* "count" has internal linkage */
static
void
foo
(
void
)
/* "foo" has internal linkage */
{
int16_t
count
;
/* Non-compliant - "count" has no linkage
* but clashes with an identifier with
* internal linkage */
int16_t
index
;
/* "index" has no linkage */
}
void
bar1
(
void
)
{
static
int16_t
count
;
/* Non-compliant - "count" has no linkage
* but clashes with an identifier with
* internal linkage */
int16_t
index
;
/* Compliant - "index" is not unique but
* has no linkage */
foo
(
);
}
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.5.9/R.5.9-file2.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
static
int8_t
count
;
/* Non-compliant - "count" has internal
* linkage but clashes with other
* identifiers of the same name */
static
void
foo
(
void
)
/* Non-compliant - "foo" has internal
* linkage but clashes with a function of
* the same name */
{
int32_t
index
;
/* Compliant - both "index" and "nbytes" */
int16_t
nbytes
;
/* are not unique but have no linkage */
}
void
bar2
(
void
)
{
static
uint8_t
nbytes
;
/* Compliant - "nbytes" is not unique but
* has no linkage and the storage class is
* irrelevant */
}
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.6.1/R.6.1.c
0 → 100644
View file @
2a291a73
// Example code from MISRA C:2012 begin
typedef
unsigned
int
UINT_16
;
struct
s
{
unsigned
int
b1
:
2
;
/* Compliant */
int
b2
:
2
;
/* Non-compliant - plain int not permitted */
UINT_16
b3
:
2
;
/* Compliant - typedef designating unsigned int */
signed
long
b4
:
2
;
/* Non-compliant even if long and int are the
* same size */
};
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.7.1/R.7.1.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
void
test
(
void
)
{
// Example code from MISRA C:2012 begin
extern
uint16_t
code
[
10
];
code
[
1
]
=
109
;
/* Compliant - decimal 109 */
code
[
2
]
=
100
;
/* Compliant - decimal 100 */
code
[
3
]
=
052
;
/* Non-compliant - decimal 42 */
code
[
4
]
=
071
;
/* Non-compliant - decimal 57 */
// Example code from MISRA C:2012 end
}
BM-MISRA-C 2012/R.7.3/R.7.3.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
const
int64_t
a
=
0L
;
const
int64_t
b
=
0l
;
/* Non-compliant */
const
uint64_t
c
=
0Lu
;
const
uint64_t
d
=
0lU
;
/* Non-compliant */
const
uint64_t
e
=
0ULL
;
const
uint64_t
f
=
0Ull
;
/* Non-compliant */
const
int128_t
g
=
0LL
;
const
int128_t
h
=
0ll
;
/* Non-compliant */
const
float128_t
m
=
1
.
2L
;
const
float128_t
n
=
2
.
4l
;
/* Non-compliant */
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.7.4/R.7.4.c
0 → 100644
View file @
2a291a73
void
badAttempt
(
void
)
{
// Example code from MISRA C:2012 begin
"0123456789"
[
0
]
=
'*'
;
/* Non-compliant */
// Example code from MISRA C:2012 end
}
// Example code from MISRA C:2012 begin
/* Non-compliant - s is not const-qualified */
char
*
s
=
"string"
;
/* Compliant - p is const-qualified; additional qualifiers are permitted */
const
volatile
char
*
p
=
"string"
;
extern
void
f1
(
char
*
s1
);
extern
void
f2
(
const
char
*
s2
);
void
g
(
void
)
{
f1
(
"string"
);
/* Non-compliant - parameter s1 is not
* const-qualified */
f2
(
"string"
);
/* Compliant */
}
char
*
name1
(
void
)
{
return
(
"MISRA"
);
/* Non-compliant - return type is not
* const-qualified */
}
const
char
*
name2
(
void
)
{
return
(
"MISRA"
);
/* Compliant */
}
// Example code from MISRA C:2012 end
BM-MISRA-C 2012/R.8.1/R.8.1.c
0 → 100644
View file @
2a291a73
#include "../include/typedefs.h"
// Example code from MISRA C:2012 begin
extern
x
;
/* Non-compliant */
extern
int32_t
x
;
/* Compliant */
const
y
;
/* Non-compliant */
const
int32_t
y
;
/* Compliant */
extern
f
(
void
);
/* Non-compliant */
extern
int32_t
f
(
void
);
/* Compliant */
extern
void
g
(
char
c
,
const
k
);
/* Non-compliant */
extern
void
g
(
char
c
,
const
int32_t
k
);
/* Compliant */
typedef
(
*
pfi
)
(
void
);
/* Non-compliant */
typedef
int32_t
(
*
pfi
)
(
void
);
/* Compliant */
typedef
void
(
*
pfv
)
(
const
x
);
/* Non-compliant */
typedef
void
(
*
pfv
)
(
int32_t
x
);
/* Compliant */
struct
str
{
int16_t
x
;
/* Compliant */
const
y
;
/* Non-compliant */
}
s
;
// Example code from MISRA C:2012 end
Prev
1
…
27
28
29
30
31
32
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment