...
Noncompliant Code Example
The following This noncompliant code example logs the program's state at runtime.
| Code Block | ||
|---|---|---|
| ||
void do_stuff(void) {
FILE *logfile = fopen("log", "a");
if (logfile == NULL) {
/* handleHandle error */
}
/* writeWrite logs pertaining to do_stuff() */
/* ... */
}
int main(void) {
FILE *logfile = fopen("log", "a");
if (logfile == NULL) {
/* handleHandle error */
}
/* writeWrite logs pertaining to main() */
do_stuff();
/* ... */
}
|
...
| Code Block | ||
|---|---|---|
| ||
void do_stuff(FILE *logfile) {
/* writeWrite logs pertaining to do_stuff() */
/* ... */
}
int main(void) {
FILE *logfile = fopen("log", "a");
if (logfile == NULL) {
/* handleHandle error */
}
/* writeWrite logs pertaining to main() */
do_stuff(logfile);
/* ... */
}
|
...
| Wiki Markup |
|---|
\[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] Section 7.19.3, "Files"
\[[MITRE 07|AA. C References#MITRE 07]\] [CWE ID 362|http://cwe.mitre.org/data/definitions/362.html], "Race Condition," [CWE ID 675|http://cwe.mitre.org/data/definitions/675.html], and "Duplicate Operations on Resource" |
...