Skip to content

Commit 352f778

Browse files
committed
Handle non-zero length characters
1 parent 006e4a1 commit 352f778

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

c/misra/src/codingstandards/c/misra/EssentialTypes.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,11 @@ class EssentialEnumConstantAccess extends EssentialExpr, EnumConstantAccess {
393393
class EssentialLiteral extends EssentialExpr, Literal {
394394
override Type getEssentialType() {
395395
if this instanceof BooleanLiteral
396-
then result instanceof MisraBoolType
396+
then
397+
// This returns a multitude of types - not sure if we really want that
398+
result instanceof MisraBoolType
397399
else (
398-
if this.(CharLiteral).getCharacter().length() = 1
400+
if this instanceof CharLiteral
399401
then result instanceof PlainCharType
400402
else
401403
exists(Type underlyingStandardType |

c/misra/test/c/misra/EssentialTypes.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@
8787
| test.c:73:3:73:5 | EC4 | (unnamed enum) | (unnamed enum) | essentially Enum Type |
8888
| test.c:74:3:74:5 | EC5 | (unnamed enum) | (unnamed enum) | essentially Enum Type |
8989
| test.c:75:3:75:5 | EC6 | (unnamed enum) | (unnamed enum) | essentially Enum Type |
90+
| test.c:79:3:79:5 | 97 | char | char | essentially Character type |
91+
| test.c:80:3:80:6 | 10 | char | char | essentially Character type |
92+
| test.c:81:3:81:6 | 0 | char | char | essentially Character type |

c/misra/test/c/misra/test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ void testEnums() {
7373
EC4; // Should be essentially enum
7474
EC5; // Should be essentially enum
7575
EC6; // Should be essentially enum
76+
}
77+
78+
void testControlChar() {
79+
'a'; // Essentially char
80+
'\n'; // Essentially char
81+
'\0'; // Essentially char
7682
}

0 commit comments

Comments
 (0)