CPP: Add a test of AV Rule 165.

This commit is contained in:
Geoffrey White
2018-11-14 19:05:35 +00:00
parent bc06831d01
commit 5cddabb1fd
3 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
| test.c:6:6:6:8 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:9:7:9:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:12:7:12:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:18:7:18:14 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:19:7:19:23 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:20:7:20:21 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:22:8:22:11 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:23:8:23:11 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:24:6:24:7 | - ... | The unary minus operator should not be applied to an unsigned expression. |
| test.c:25:7:25:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |

View File

@@ -0,0 +1 @@
jsf/4.21 Operators/AV Rule 165.ql

View File

@@ -0,0 +1,27 @@
typedef unsigned int TUI;
void f(int i, unsigned int ui, signed int si, TUI tui, volatile unsigned int vui, unsigned u, unsigned short us) {
i = -i;
i = -ui; // BAD
i = -si;
ui = -i;
ui = -ui; // BAD
ui = -si;
si = -i;
si = -ui; // BAD
si = -si;
i = -(int)i;
i = -(unsigned int)i; // BAD [NOT DETECTED]
i = -(signed int)i;
ui = -(int)ui; // [FALSE POSITIVE]
ui = -(unsigned int)ui; // BAD
ui = -(signed int)ui; // [FALSE POSITIVE]
tui = -tui; // BAD
vui = -vui; // BAD
u = -u; // BAD
us = -us; // BAD
ui = -(5U); // BAD [NOT DETECTED]
}