Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
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 &lt;< MAX; i++) {
    out[i] = helper(i);
  }

  /* ... */

}

...

Code Block
bgColor#ccccff
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 &lt;< 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, &quot;"Linkages of identifiers&quot;"

...

DCL14-C. Do not make assumptions about the order of global variable initialization across translation units&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      02. Declarations and Initialization (DCL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;