From b6a4f67a73f20acadc89a8f016372f64b7286a81 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Mon, 12 Feb 2024 22:14:45 -0500 Subject: [PATCH 1/6] A18-0-1: improve query logic --- change_notes/2024-02-12-improve-a18-0-1.md | 2 ++ .../CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql | 5 +++-- cpp/autosar/test/rules/A18-0-1/lib/assert.h | 4 ++++ cpp/autosar/test/rules/A18-0-1/test.cpp | 4 +++- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 change_notes/2024-02-12-improve-a18-0-1.md create mode 100644 cpp/autosar/test/rules/A18-0-1/lib/assert.h diff --git a/change_notes/2024-02-12-improve-a18-0-1.md b/change_notes/2024-02-12-improve-a18-0-1.md new file mode 100644 index 0000000000..4ad186b0ae --- /dev/null +++ b/change_notes/2024-02-12-improve-a18-0-1.md @@ -0,0 +1,2 @@ +`A18-0-1` - `CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql`: + - Improve query logic to only match on exact standard library names (exclude local files with same names. Now excludes sys/header.h type headers as well from the results as those are not C standard libraries). \ No newline at end of file diff --git a/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql b/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql index ada60f305d..9a5970c870 100644 --- a/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql +++ b/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql @@ -28,12 +28,13 @@ where * not use any of 'signal.h's facilities, for example. */ - filename = i.getIncludedFile().getBaseName() and + filename = i.getIncludeText().substring(1, i.getIncludeText().length() - 1) and filename in [ "assert.h", "ctype.h", "errno.h", "fenv.h", "float.h", "inttypes.h", "limits.h", "locale.h", "math.h", "setjmp.h", "signal.h", "stdarg.h", "stddef.h", "stdint.h", "stdio.h", "stdlib.h", "string.h", "time.h", "uchar.h", "wchar.h", "wctype.h" - ] + ] and + not exists(i.getIncludedFile().getRelativePath()) select i, "C library \"" + filename + "\" is included instead of the corresponding C++ library ." diff --git a/cpp/autosar/test/rules/A18-0-1/lib/assert.h b/cpp/autosar/test/rules/A18-0-1/lib/assert.h new file mode 100644 index 0000000000..001980b02f --- /dev/null +++ b/cpp/autosar/test/rules/A18-0-1/lib/assert.h @@ -0,0 +1,4 @@ +#ifndef LIB_EXAMPLE_H_ +#define LIB_EXAMPLE_H_ + +#endif \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-0-1/test.cpp b/cpp/autosar/test/rules/A18-0-1/test.cpp index b095017685..7c54ccf98e 100644 --- a/cpp/autosar/test/rules/A18-0-1/test.cpp +++ b/cpp/autosar/test/rules/A18-0-1/test.cpp @@ -39,4 +39,6 @@ #include // COMPLIANT #include // COMPLIANT #include // COMPLIANT -#include // COMPLIANT \ No newline at end of file +#include // COMPLIANT + +#include "lib/assert.h" // COMPLIANT \ No newline at end of file From 67d3b98346e23fdd62177f2f71e8573a064eeb3b Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Mon, 12 Feb 2024 22:20:18 -0500 Subject: [PATCH 2/6] A18-0-1: improve change note --- change_notes/2024-02-12-improve-a18-0-1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2024-02-12-improve-a18-0-1.md b/change_notes/2024-02-12-improve-a18-0-1.md index 4ad186b0ae..cd6bcee256 100644 --- a/change_notes/2024-02-12-improve-a18-0-1.md +++ b/change_notes/2024-02-12-improve-a18-0-1.md @@ -1,2 +1,2 @@ `A18-0-1` - `CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql`: - - Improve query logic to only match on exact standard library names (exclude local files with same names. Now excludes sys/header.h type headers as well from the results as those are not C standard libraries). \ No newline at end of file + - Fix issue #7 - improve query logic to only match on exact standard library names (exclude local files with same names. Now excludes sys/header.h type headers as well from the results as those are not C standard libraries). \ No newline at end of file From 65f71d9e5361103831fc6a299d95d6fa07c6c76c Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Fri, 16 Feb 2024 10:02:17 -0500 Subject: [PATCH 3/6] Update change_notes/2024-02-12-improve-a18-0-1.md Co-authored-by: Remco Vermeulen --- change_notes/2024-02-12-improve-a18-0-1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2024-02-12-improve-a18-0-1.md b/change_notes/2024-02-12-improve-a18-0-1.md index cd6bcee256..5ad807faba 100644 --- a/change_notes/2024-02-12-improve-a18-0-1.md +++ b/change_notes/2024-02-12-improve-a18-0-1.md @@ -1,2 +1,2 @@ -`A18-0-1` - `CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql`: +- `A18-0-1` - `CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql`: - Fix issue #7 - improve query logic to only match on exact standard library names (exclude local files with same names. Now excludes sys/header.h type headers as well from the results as those are not C standard libraries). \ No newline at end of file From df07198e0aa6cec5858e46212f36c8b93b85e89f Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Fri, 16 Feb 2024 10:53:05 -0500 Subject: [PATCH 4/6] A18-0-1: improve testcase --- cpp/autosar/test/rules/A18-0-1/test.cpp | 3 ++- cpp/autosar/test/rules/A18-0-1/time.h | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 cpp/autosar/test/rules/A18-0-1/time.h diff --git a/cpp/autosar/test/rules/A18-0-1/test.cpp b/cpp/autosar/test/rules/A18-0-1/test.cpp index 7c54ccf98e..77ed9f94f0 100644 --- a/cpp/autosar/test/rules/A18-0-1/test.cpp +++ b/cpp/autosar/test/rules/A18-0-1/test.cpp @@ -41,4 +41,5 @@ #include // COMPLIANT #include // COMPLIANT -#include "lib/assert.h" // COMPLIANT \ No newline at end of file +#include "lib/assert.h" // COMPLIANT +#include "time.h" // COMPLIANT - no way to check if this is a local checked in std lib copy \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-0-1/time.h b/cpp/autosar/test/rules/A18-0-1/time.h new file mode 100644 index 0000000000..ba58b95bbc --- /dev/null +++ b/cpp/autosar/test/rules/A18-0-1/time.h @@ -0,0 +1,4 @@ +#ifndef LIB_TIME_EXAMPLE_H_ +#define LIB_TIME_EXAMPLE_H_ +// may be a user lib or a std lib checked into a project +#endif \ No newline at end of file From 449d90f66d2038d13d771d68087976eee72ddce4 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Fri, 16 Feb 2024 20:58:39 -0500 Subject: [PATCH 5/6] A18-0-1: improve heuristic and test --- .../CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql | 3 +-- ...raryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected | 1 + cpp/autosar/test/rules/A18-0-1/lib/{assert.h => example.h} | 0 cpp/autosar/test/rules/A18-0-1/test.cpp | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename cpp/autosar/test/rules/A18-0-1/lib/{assert.h => example.h} (100%) diff --git a/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql b/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql index 9a5970c870..5c4d9d580f 100644 --- a/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql +++ b/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql @@ -33,8 +33,7 @@ where "assert.h", "ctype.h", "errno.h", "fenv.h", "float.h", "inttypes.h", "limits.h", "locale.h", "math.h", "setjmp.h", "signal.h", "stdarg.h", "stddef.h", "stdint.h", "stdio.h", "stdlib.h", "string.h", "time.h", "uchar.h", "wchar.h", "wctype.h" - ] and - not exists(i.getIncludedFile().getRelativePath()) + ] select i, "C library \"" + filename + "\" is included instead of the corresponding C++ library ." diff --git a/cpp/autosar/test/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected b/cpp/autosar/test/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected index 3952555595..ff53ffd841 100644 --- a/cpp/autosar/test/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected +++ b/cpp/autosar/test/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected @@ -19,3 +19,4 @@ | test.cpp:19:1:19:18 | #include | C library "uchar.h" is included instead of the corresponding C++ library . | | test.cpp:20:1:20:18 | #include | C library "wchar.h" is included instead of the corresponding C++ library . | | test.cpp:21:1:21:19 | #include | C library "wctype.h" is included instead of the corresponding C++ library . | +| test.cpp:45:1:45:17 | #include "time.h" | C library "time.h" is included instead of the corresponding C++ library . | diff --git a/cpp/autosar/test/rules/A18-0-1/lib/assert.h b/cpp/autosar/test/rules/A18-0-1/lib/example.h similarity index 100% rename from cpp/autosar/test/rules/A18-0-1/lib/assert.h rename to cpp/autosar/test/rules/A18-0-1/lib/example.h diff --git a/cpp/autosar/test/rules/A18-0-1/test.cpp b/cpp/autosar/test/rules/A18-0-1/test.cpp index 77ed9f94f0..579842ddab 100644 --- a/cpp/autosar/test/rules/A18-0-1/test.cpp +++ b/cpp/autosar/test/rules/A18-0-1/test.cpp @@ -41,5 +41,5 @@ #include // COMPLIANT #include // COMPLIANT -#include "lib/assert.h" // COMPLIANT -#include "time.h" // COMPLIANT - no way to check if this is a local checked in std lib copy \ No newline at end of file +#include "lib/example.h" // COMPLIANT +#include "time.h" // NON_COMPLIANT \ No newline at end of file From ba85afc6f75c318d8832dcb5947354e1d08046a9 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Mon, 26 Feb 2024 08:56:56 -0500 Subject: [PATCH 6/6] Update change_notes/2024-02-12-improve-a18-0-1.md Co-authored-by: Remco Vermeulen --- change_notes/2024-02-12-improve-a18-0-1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2024-02-12-improve-a18-0-1.md b/change_notes/2024-02-12-improve-a18-0-1.md index 5ad807faba..a4a9613a45 100644 --- a/change_notes/2024-02-12-improve-a18-0-1.md +++ b/change_notes/2024-02-12-improve-a18-0-1.md @@ -1,2 +1,2 @@ - `A18-0-1` - `CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql`: - - Fix issue #7 - improve query logic to only match on exact standard library names (exclude local files with same names. Now excludes sys/header.h type headers as well from the results as those are not C standard libraries). \ No newline at end of file + - Fix issue #7 - improve query logic to only match on exact standard library names (e.g., now excludes sys/header.h type headers from the results as those are not C standard libraries). \ No newline at end of file