@@ -94,8 +94,8 @@ and other misbehavior due to the missing termination. It also NUL-pads the
94
94
destination buffer if the source contents are shorter than the destination
95
95
buffer size, which may be a needless performance penalty for callers using
96
96
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() .)
99
99
100
100
If a caller is using non-NUL-terminated strings, :c:func: `strncpy() ` can
101
101
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`)
144
144
145
145
Implicit switch case fall-through
146
146
---------------------------------
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
+ }
150
163
151
164
As there have been a long list of flaws `due to missing "break" statements
152
165
<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
161
171
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.)
163
173
164
174
All switch/case blocks must end in one of:
165
175
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