Skip to content

Commit 4e25929

Browse files
authored
Merge pull request #288 from geoffw0/widechartype
CPP: Address Widechartype / WChar_t
2 parents 887daec + e0140f9 commit 4e25929

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

cpp/ql/src/Likely Bugs/Format/NonConstantFormat.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ predicate stringType(Type t, Type charType) {
2525
charType = t.(ArrayType).getBaseType()
2626
) and (
2727
charType.getUnspecifiedType() instanceof CharType or
28-
charType.getUnspecifiedType() instanceof WideCharType
28+
charType.getUnspecifiedType() instanceof Wchar_t
2929
)
3030
)
3131
or

cpp/ql/src/Security/CWE/CWE-676/DangerousUseOfCin.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import cpp
1919
class AnyCharPointerType extends PointerType {
2020
AnyCharPointerType() {
2121
this.getBaseType().getUnderlyingType() instanceof CharType or
22-
this.getBaseType().getUnderlyingType() instanceof WideCharType
22+
this.getBaseType().getUnderlyingType() instanceof Wchar_t
2323
}
2424
}
2525

@@ -29,7 +29,7 @@ class AnyCharPointerType extends PointerType {
2929
class AnyCharArrayType extends ArrayType {
3030
AnyCharArrayType() {
3131
this.getBaseType().getUnderlyingType() instanceof CharType or
32-
this.getBaseType().getUnderlyingType() instanceof WideCharType
32+
this.getBaseType().getUnderlyingType() instanceof Wchar_t
3333
}
3434
}
3535

cpp/ql/src/semmle/code/cpp/Type.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@ class VoidType extends BuiltInType {
601601

602602
/**
603603
* The C/C++ wide character type.
604+
*
605+
* Note that on some platforms `wchar_t` doesn't exist as a built-in
606+
* type but a typedef is provided. Consider using the `Wchar_t` QL
607+
* class to include these types.
604608
*/
605609
class WideCharType extends IntegralType {
606610

cpp/ql/src/semmle/code/cpp/commons/CommonType.qll

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import semmle.code.cpp.Type
22

33
/**
4-
* The C/C++ char* type.
4+
* The C/C++ `char*` type.
55
*/
66
class CharPointerType extends PointerType {
77

@@ -10,7 +10,7 @@ class CharPointerType extends PointerType {
1010
}
1111

1212
/**
13-
* The C/C++ int* type.
13+
* The C/C++ `int*` type.
1414
*/
1515
class IntPointerType extends PointerType {
1616

@@ -20,7 +20,7 @@ class IntPointerType extends PointerType {
2020

2121

2222
/**
23-
* The C/C++ void* type.
23+
* The C/C++ `void*` type.
2424
*/
2525
class VoidPointerType extends PointerType {
2626

@@ -29,7 +29,7 @@ class VoidPointerType extends PointerType {
2929
}
3030

3131
/**
32-
* The C/C++ size_t type.
32+
* The C/C++ `size_t` type.
3333
*/
3434
class Size_t extends Type {
3535
Size_t() {
@@ -39,7 +39,7 @@ class Size_t extends Type {
3939
}
4040

4141
/**
42-
* The C/C++ ssize_t type.
42+
* The C/C++ `ssize_t` type.
4343
*/
4444
class Ssize_t extends Type {
4545
Ssize_t() {
@@ -49,7 +49,7 @@ class Ssize_t extends Type {
4949
}
5050

5151
/**
52-
* The C/C++ ptrdiff_t type.
52+
* The C/C++ `ptrdiff_t` type.
5353
*/
5454
class Ptrdiff_t extends Type {
5555
Ptrdiff_t() {
@@ -59,7 +59,7 @@ class Ptrdiff_t extends Type {
5959
}
6060

6161
/**
62-
* The C/C++ intmax_t type.
62+
* The C/C++ `intmax_t` type.
6363
*/
6464
class Intmax_t extends Type {
6565
Intmax_t() {
@@ -69,7 +69,7 @@ class Intmax_t extends Type {
6969
}
7070

7171
/**
72-
* The C/C++ uintmax_t type.
72+
* The C/C++ `uintmax_t` type.
7373
*/
7474
class Uintmax_t extends Type {
7575
Uintmax_t() {
@@ -79,7 +79,11 @@ class Uintmax_t extends Type {
7979
}
8080

8181
/**
82-
* The C/C++ wchar_t type.
82+
* The C/C++ `wchar_t` type.
83+
*
84+
* Note that on some platforms `wchar_t` doesn't exist as a built-in
85+
* type but a typedef is provided. This QL class includes both cases
86+
* (see also `WideCharType`).
8387
*/
8488
class Wchar_t extends Type {
8589
Wchar_t() {

0 commit comments

Comments
 (0)