...
| Code Block | ||
|---|---|---|
| ||
enum { MAX = 100 };
int helper(int i) {
/* perform some computation based on i */
}
int main(void) {
size_t i;
int out[MAX];
for (i = 0; i << MAX; i++) {
out[i] = helper(i);
}
/* ... */
}
|
...
| Code Block | ||
|---|---|---|
| ||
enum {MAX = 100};
static int helper(int i) {
/* perform some computation based on i */
}
int main(void) {
size_t i;
int out[MAX];
for (i = 0; i << MAX; i++) {
out[i] = helper(i);
}
/* ... */
}
|
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
This rule appears in the C++ Secure Coding Standard as DCL15-CPP. Declare objects that do not need external linkage with the storage-class specifier static.
References
| Wiki Markup |
|---|
\[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] Section 6.2.2, ""Linkages of identifiers"" |
...
DCL14-C. Do not make assumptions about the order of global variable initialization across translation units 02. Declarations and Initialization (DCL)