mirror of
https://github.com/github/codeql.git
synced 2026-03-31 12:48:17 +02:00
C++: Add test cases emulating cpp/suspicious-add-sizeof in buildless mode.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
| buildless.cpp:5:15:5:25 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const short * | const short * |
|
||||
| buildless.cpp:6:13:6:23 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const int * | const int * |
|
||||
| buildless.cpp:7:11:7:21 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const <error-type> * | const <error-type> * |
|
||||
| buildless.cpp:8:12:8:22 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const <error-type> * | const <error-type> * |
|
||||
| buildless.cpp:9:12:9:22 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | const <error-type> * | const <error-type> * |
|
||||
| test.cpp:6:30:6:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
|
||||
| test.cpp:14:30:14:40 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
|
||||
| test.cpp:22:25:22:35 | sizeof(int) | Suspicious sizeof offset in a pointer arithmetic expression. The type of the pointer is $@. | file://:0:0:0:0 | int * | int * |
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// semmle-extractor-options: --expect_errors
|
||||
|
||||
void test_buildless(const char *p_c, const short *p_short, const int *p_int, const uint8_t *p_8, const uint16_t *p_16, const uint32_t *p_32) {
|
||||
*(p_c + sizeof(int)); // GOOD (`sizeof(char)` is 1)
|
||||
*(p_short + sizeof(int)); // BAD
|
||||
*(p_int + sizeof(int)); // BAD
|
||||
*(p_8 + sizeof(int)); // GOOD (`sizeof(p_8)` is 1) [FALSE POSITIVE]
|
||||
*(p_16 + sizeof(int)); // BAD
|
||||
*(p_32 + sizeof(int)); // BAD
|
||||
}
|
||||
@@ -93,3 +93,9 @@ private:
|
||||
myChar * const myCharsPointer;
|
||||
myInt * const myIntsPointer;
|
||||
};
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
|
||||
void test_buildless(const char *p_c, const short *p_short, const int *p_int, const uint8_t *p_8, const uint16_t *p_16, const uint32_t *p_32);
|
||||
|
||||
Reference in New Issue
Block a user