C++: handle __uuidof(0)

This commit is contained in:
Nick Rolfe
2018-10-29 12:49:34 +00:00
parent 3e171960dc
commit 9a412c9202
3 changed files with 8 additions and 1 deletions

View File

@@ -497,7 +497,12 @@ class DynamicCast extends Cast, @dynamic_cast {
* specified by the `__declspec(uuid)` attribute.
*/
class UuidofOperator extends Expr, @uuidof {
override string toString() { result = "__uuidof(" + getTypeOperand().getName() + ")" }
override string toString() {
if exists(getTypeOperand()) then
result = "__uuidof(" + getTypeOperand().getName() + ")"
else
result = "__uuidof(0)"
}
override int getPrecedence() { result = 15 }

View File

@@ -15,5 +15,6 @@ void GetUUID() {
uuid = __uuidof(Templ<S>);
S s;
uuid = __uuidof(s);
uuid = __uuidof(0);
}
// semmle-extractor-options: --microsoft

View File

@@ -11,3 +11,4 @@ uuidofOperators
| uuidof.cpp:14:12:14:30 | __uuidof(S) | const _GUID | 01234567-89ab-cdef-0123-456789abcdef |
| uuidof.cpp:15:12:15:29 | __uuidof(S) | const _GUID | 01234567-89ab-cdef-0123-456789abcdef |
| uuidof.cpp:17:12:17:22 | __uuidof(S) | const _GUID | 01234567-89ab-cdef-0123-456789abcdef |
| uuidof.cpp:18:12:18:22 | __uuidof(0) | const _GUID | 00000000-0000-0000-0000-000000000000 |