Skip to content

Commit ea05a21

Browse files
committed
Proof of concept for guideline references
1 parent 1c7d6bb commit ea05a21

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/appendices/standards-matrices.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55

66
Standards Matrices
77
==================
8+
9+
MISRA C
10+
~~~~~~~
11+
12+
.. needlist::
13+
:filter: misra != "" and type == "guideline"

src/coding-guidelines/associated-items/gui_ot2Zt3dd6of1.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@ Recursive function are not allowed
77
==================================
88

99
.. guideline:: Recursive function are not allowed
10-
:id: gui_ot2Zt3dd6of1
10+
:id: gui_ot2Zt3dd6of1
1111
:category: required
1212
:status: draft
1313
:release: 1.3.0-latest
1414
:fls: fls_vjgkg8kfi93
1515
:decidability: undecidable
1616
:scope: system
1717
:tags: stack-overflow
18+
:misra: test
1819

1920
Any function shall not call itself directly or indirectly
2021

21-
.. rationale::
22-
:id: rat_gvoKeVSKK8fD
22+
.. rationale::
23+
:id: rat_gvoKeVSKK8fD
2324
:status: draft
2425

2526
Recursive functions can easily cause stack overflows, which may result in exceptions or, in some cases, undefined behavior (typically some embedded systems). Although the Rust compiler supports tail call optimization :cite:`gui_ot2Zt3dd6of1:WIKI-TAIL-CALL`, this optimization is not guaranteed and depends on the specific implementation and function structure. There is an open RFC to guarantee tail call optimization in the Rust compiler :cite:`gui_ot2Zt3dd6of1:PROPOSED-RFC-EXPLICIT-TAIL-CALLS`, but this feature has not yet been stabilized. Until tail call optimization is guaranteed and stabilized, developers should avoid using recursive functions to prevent potential stack overflows and ensure program reliability.
2627

2728
.. non_compliant_example::
28-
:id: non_compl_ex_MxqhjfkStJJy
29+
:id: non_compl_ex_MxqhjfkStJJy
2930
:status: draft
3031

3132
The below function ``concat_strings`` is not complaint because it call itself and depending on depth of data provided as input it could generate an stack overflow exception or undefine behavior.
@@ -55,7 +56,7 @@ Recursive function are not allowed
5556
# fn main() {}
5657

5758
.. compliant_example::
58-
:id: compl_ex_9pK3h65rfceO
59+
:id: compl_ex_9pK3h65rfceO
5960
:status: draft
6061

6162
The following code implements the same functionality using iteration instead of recursion. The ``stack`` variable is used to maintain the processing context at each step of the loop. This approach provides explicit control over memory usage. If the stack grows beyond a predefined limit due to the structure or size of the input, the function returns an error rather than risking a stack overflow or out-of-memory exception. This ensures more predictable and robust behavior in resource-constrained environments.

src/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"non_compliant_example",
8080
"compliant_example",
8181
"bibliography",
82+
"misra",
8283
]
8384
}
8485
}
@@ -92,6 +93,7 @@
9293
"non_compliant_example",
9394
"non_compliant_example",
9495
"bibliography",
96+
"misra",
9597
],
9698
}
9799
}
@@ -191,13 +193,14 @@
191193
]
192194

193195
# Enable needs export
194-
needs_extra_options = [
196+
needs_fields = [
195197
"category",
196198
"recommendation",
197199
"fls",
198200
"decidability",
199201
"scope",
200202
"release",
203+
"misra",
201204
]
202205

203206

0 commit comments

Comments
 (0)