...
The following This noncompliant code example contains references to headers that may exist independently in various environments but can be ambiguously interpreted by a C-compliant compiler:
Code Block |
---|
|
#include "Library.h"
#include <stdio.h>
#include <stdlib.h>
#include "library.h"
#include "utilities_math.h"
#include "utilities_physics.h"
#include "my_library.h"
/* Rest of program ... */
|
Library.h
and library.h
may refer to the same file. Also, because only the first eight characters are guaranteed to be significant, it is unclear whether utilities_math.h
and utilities_physics.h
are parsed. Finally, if a file such as my_libraryOLD.h
exists, it may inadvertently be included instead of my_library.h
.
...
Code Block |
---|
|
#include "Lib_main.h"
#include <stdio.h>
#include <stdlib.h>
#include "lib_2.h"
#include "util_math.h"
#include "util_physics.h"
#include "my_library.h"
/* Rest of program ... */
|
The only solution for mitigating ambiguity of a file, such as my_libraryOLD.h
, is to rename old files with either a prefix (that would fall within the first eight characters) or add an extension (such as my_library.h.old
).
PRE08-C-EX1: Although the C Standard requires only the first eight characters in the file name to be significant, most modern systems have long file names, and compilers on such systems can typically differentiate them. Consequently, long file names in headers may be used, provided that all the implementations to which the code is ported can distinguish between these file names.
...
Failing to guarantee uniqueness of header files may result in the inclusion of an older version of a header file, which may include incorrect macro definitions or obsolete function prototypes or result in other errors that may or may not be detected by the compiler. Portability issues may also stem from the use of header names that are not guaranteed to be unique.
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|
PRE08-C |
lowunlikelymediumTool | Version | Checker | Description |
---|
ECLAIRECLAIRECLAIRCC2.Fully implemented | KlocworkKlocworkKlocworkIF_DUPL_HEADER | | PRQA QA-CPRQAPRQAFully implementedSecondary Analysis | Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
Image Modified Image Modified Image Modified