forked fromtorvalds/linux
- Notifications
You must be signed in to change notification settings - Fork0
Commit04f5c36
sched/fair: Replace zero-length array with flexible-array
The current codebase makes use of the zero-length array languageextension to the C90 standard, but the preferred mechanism to declarevariable-length types such as these ones is a flexible array member[1][2],introduced in C99:struct foo { int stuff; struct boo array[];};By making use of the mechanism above, we will get a compiler warningin case the flexible array does not occur last in the structure, whichwill help us prevent some kind of undefined behavior bugs from beinginadvertently introduced[3] to the codebase from now on.Also, notice that, dynamic memory allocations won't be affected bythis change:"Flexible array members have incomplete type, and so the sizeof operatormay not be applied. As a quirk of the original implementation ofzero-length arrays, sizeof evaluates to zero."[1]sizeof(flexible-array-member) triggers a warning because flexible arraymembers have incomplete type[1]. There are some instances of code inwhich the sizeof operator is being incorrectly/erroneously applied tozero-length arrays and the result is zero. Such instances may be hidingsome bugs. So, this work (flexible-array member conversions) will alsohelp to get completely rid of those sorts of issues.This issue was found with the help of Coccinelle.[1]https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html[2]KSPP#21[3] commit7649773 ("cxgb3/l2t: Fix undefined behaviour")Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>Link:https://lkml.kernel.org/r/20200507192141.GA16183@embeddedor1 parent95d6859 commit04f5c36
2 files changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1094 | 1094 | | |
1095 | 1095 | | |
1096 | 1096 | | |
1097 | | - | |
| 1097 | + | |
1098 | 1098 | | |
1099 | 1099 | | |
1100 | 1100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1462 | 1462 | | |
1463 | 1463 | | |
1464 | 1464 | | |
1465 | | - | |
| 1465 | + | |
1466 | 1466 | | |
1467 | 1467 | | |
1468 | 1468 | | |
| |||
0 commit comments
Comments
(0)