Skip to content

Commit 76136e0

Browse files
keesJonathan Corbet
authored andcommitted
docs: deprecated.rst: Clean up fall-through details
Add example of fall-through, list-ify the case ending statements, and adjust the markup for links and readability. While here, adjust strscpy() details to mention strscpy_pad(). Signed-off-by: Kees Cook <[email protected]> Acked-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/r/202003041102.47A4E4B62@keescook Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 6505a18 commit 76136e0

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

Documentation/process/deprecated.rst

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ and other misbehavior due to the missing termination. It also NUL-pads the
9494
destination buffer if the source contents are shorter than the destination
9595
buffer size, which may be a needless performance penalty for callers using
9696
only NUL-terminated strings. The safe replacement is :c:func:`strscpy`.
97-
(Users of :c:func:`strscpy` still needing NUL-padding will need an
98-
explicit :c:func:`memset` added.)
97+
(Users of :c:func:`strscpy` still needing NUL-padding should instead
98+
use strscpy_pad().)
9999

100100
If a caller is using non-NUL-terminated strings, :c:func:`strncpy()` can
101101
still be used, but destinations should be marked with the `__nonstring
@@ -144,27 +144,37 @@ memory adjacent to the stack (when built without `CONFIG_VMAP_STACK=y`)
144144

145145
Implicit switch case fall-through
146146
---------------------------------
147-
The C language allows switch cases to "fall-through" when a "break" statement
148-
is missing at the end of a case. This, however, introduces ambiguity in the
149-
code, as it's not always clear if the missing break is intentional or a bug.
147+
The C language allows switch cases to fall through to the next case
148+
when a "break" statement is missing at the end of a case. This, however,
149+
introduces ambiguity in the code, as it's not always clear if the missing
150+
break is intentional or a bug. For example, it's not obvious just from
151+
looking at the code if `STATE_ONE` is intentionally designed to fall
152+
through into `STATE_TWO`::
153+
154+
switch (value) {
155+
case STATE_ONE:
156+
do_something();
157+
case STATE_TWO:
158+
do_other();
159+
break;
160+
default:
161+
WARN("unknown state");
162+
}
150163

151164
As there have been a long list of flaws `due to missing "break" statements
152165
<https://cwe.mitre.org/data/definitions/484.html>`_, we no longer allow
153-
"implicit fall-through".
154-
155-
In order to identify intentional fall-through cases, we have adopted a
156-
pseudo-keyword macro 'fallthrough' which expands to gcc's extension
157-
__attribute__((__fallthrough__)). `Statement Attributes
158-
<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_
159-
160-
When the C17/C18 [[fallthrough]] syntax is more commonly supported by
166+
implicit fall-through. In order to identify intentional fall-through
167+
cases, we have adopted a pseudo-keyword macro "fallthrough" which
168+
expands to gcc's extension `__attribute__((__fallthrough__))
169+
<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_.
170+
(When the C17/C18 `[[fallthrough]]` syntax is more commonly supported by
161171
C compilers, static analyzers, and IDEs, we can switch to using that syntax
162-
for the macro pseudo-keyword.
172+
for the macro pseudo-keyword.)
163173

164174
All switch/case blocks must end in one of:
165175

166-
break;
167-
fallthrough;
168-
continue;
169-
goto <label>;
170-
return [expression];
176+
* break;
177+
* fallthrough;
178+
* continue;
179+
* goto <label>;
180+
* return [expression];

0 commit comments

Comments
 (0)