From a10f35c2ae480caed13fa03678aa89908a69ba52 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Mon, 21 Nov 2022 09:23:54 +0000 Subject: [PATCH 1/2] M27-0-1: Permit elements defined in other headers The `std::size_t` type and the `NULL` macro are both defined in multiple headers, and therefore should not be uniquely considered part of cstdio. --- cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql | 4 ++-- cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql | 2 +- cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.expected | 1 - cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected | 3 --- cpp/autosar/test/rules/M27-0-1/test.cpp | 2 +- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql b/cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql index eadbc874f9..ccf633488e 100644 --- a/cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql +++ b/cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql @@ -22,7 +22,7 @@ from MacroInvocation mi where not isExcluded(mi, BannedLibrariesPackage::cstdioMacrosUsedQuery()) and mi.getMacroName() in [ - "BUFSIZ", "EOF", "FILENAME_MAX", "FOPEN_MAX", "L_tmpnam", "NULL", "TMP_MAX", "_IOFBF", - "IOLBF", "_IONBF", "SEEK_CUR", "SEEK_END", "SEEK_SET" + "BUFSIZ", "EOF", "FILENAME_MAX", "FOPEN_MAX", "L_tmpnam", "TMP_MAX", "_IOFBF", "IOLBF", + "_IONBF", "SEEK_CUR", "SEEK_END", "SEEK_SET" ] select mi, "Use of macro '" + mi.getMacroName() + "'." diff --git a/cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql b/cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql index 442264fad1..6fc2adaffb 100644 --- a/cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql +++ b/cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql @@ -22,5 +22,5 @@ from TypeMention tm, UserType ut where not isExcluded(tm, BannedLibrariesPackage::cstdioTypesUsedQuery()) and ut = tm.getMentionedType() and - ut.hasGlobalOrStdName(["FILE", "fpos_t", "size_t"]) + ut.hasGlobalOrStdName(["FILE", "fpos_t"]) select tm, "Use of type '" + ut.getQualifiedName() + "'." diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.expected b/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.expected index 8a48b86902..af67e45903 100644 --- a/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.expected +++ b/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.expected @@ -7,4 +7,3 @@ | test.cpp:30:29:30:37 | FOPEN_MAX | Use of macro 'FOPEN_MAX'. | | test.cpp:41:14:41:16 | EOF | Use of macro 'EOF'. | | test.cpp:50:24:50:31 | SEEK_SET | Use of macro 'SEEK_SET'. | -| test.cpp:60:10:60:13 | NULL | Use of macro 'NULL'. | diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected b/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected index 8f3971fa2a..037f54c05e 100644 --- a/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected +++ b/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected @@ -1,7 +1,4 @@ | test.cpp:4:8:4:11 | type mention | Use of type 'std::FILE'. | | test.cpp:6:8:6:13 | type mention | Use of type 'std::fpos_t'. | -| test.cpp:20:18:20:23 | type mention | Use of type 'size_t'. | -| test.cpp:21:18:21:23 | type mention | Use of type 'size_t'. | | test.cpp:34:3:34:6 | type mention | Use of type 'FILE'. | | test.cpp:36:3:36:8 | type mention | Use of type 'fpos_t'. | -| test.cpp:50:14:50:19 | type mention | Use of type 'size_t'. | diff --git a/cpp/autosar/test/rules/M27-0-1/test.cpp b/cpp/autosar/test/rules/M27-0-1/test.cpp index feb2ed476f..27447ba06a 100644 --- a/cpp/autosar/test/rules/M27-0-1/test.cpp +++ b/cpp/autosar/test/rules/M27-0-1/test.cpp @@ -57,5 +57,5 @@ void *test_cstdio_is_used() { printf("foo"); // NON_COMPLIANT puts("all done!"); // NON_COMPLIANT - return NULL; // NON_COMPLIANT + return NULL; // COMPLIANT - NULL is not uniquely defined by cstdio } \ No newline at end of file From 097092bf636c40b50f0b730446524b331f8eb0c0 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Mon, 21 Nov 2022 09:28:00 +0000 Subject: [PATCH 2/2] M27-0-1: Add change note Exclusion of `size_t` and `NULL`. --- change_notes/2022-11-21-null-sizet-not-cstdio.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 change_notes/2022-11-21-null-sizet-not-cstdio.md diff --git a/change_notes/2022-11-21-null-sizet-not-cstdio.md b/change_notes/2022-11-21-null-sizet-not-cstdio.md new file mode 100644 index 0000000000..8855fa050f --- /dev/null +++ b/change_notes/2022-11-21-null-sizet-not-cstdio.md @@ -0,0 +1,3 @@ + - `M27-0-1` + - `CstdioTypesUsed.ql` - Exclude `size_t` from this rule, as it can be provided by headers other than ``. + - `CstdioMacrosUsed.ql` - Exclude `NULL` from this rule, as it can be provided by headers other than ``.