From 2d9975d73ff89c70f16c8a9bad834809695e09e4 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Wed, 7 Dec 2022 13:15:43 +0100 Subject: [PATCH] C#: nint/System.IntPtr and nuint/System.UIntPtr are indistinguishable by the extractor. --- csharp/ql/test/library-tests/csharp11/NativeInt.cs | 11 +++++++++++ .../test/library-tests/csharp11/nativeInt.expected | 4 ++++ csharp/ql/test/library-tests/csharp11/nativeInt.ql | 12 ++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 csharp/ql/test/library-tests/csharp11/NativeInt.cs create mode 100644 csharp/ql/test/library-tests/csharp11/nativeInt.expected create mode 100644 csharp/ql/test/library-tests/csharp11/nativeInt.ql diff --git a/csharp/ql/test/library-tests/csharp11/NativeInt.cs b/csharp/ql/test/library-tests/csharp11/NativeInt.cs new file mode 100644 index 00000000000..5bee8213bdf --- /dev/null +++ b/csharp/ql/test/library-tests/csharp11/NativeInt.cs @@ -0,0 +1,11 @@ +public class NativeInt +{ + public void M1() + { + nint x1 = 0; + System.IntPtr x2 = (System.IntPtr)0; + + nuint y1 = 0; + System.UIntPtr y2 = (System.UIntPtr)0; + } +} \ No newline at end of file diff --git a/csharp/ql/test/library-tests/csharp11/nativeInt.expected b/csharp/ql/test/library-tests/csharp11/nativeInt.expected new file mode 100644 index 00000000000..d376204b945 --- /dev/null +++ b/csharp/ql/test/library-tests/csharp11/nativeInt.expected @@ -0,0 +1,4 @@ +| NativeInt.cs:5:14:5:15 | x1 | NativeInt.cs:6:23:6:24 | x2 | System.IntPtr | +| NativeInt.cs:6:23:6:24 | x2 | NativeInt.cs:5:14:5:15 | x1 | System.IntPtr | +| NativeInt.cs:8:15:8:16 | y1 | NativeInt.cs:9:24:9:25 | y2 | System.UIntPtr | +| NativeInt.cs:9:24:9:25 | y2 | NativeInt.cs:8:15:8:16 | y1 | System.UIntPtr | diff --git a/csharp/ql/test/library-tests/csharp11/nativeInt.ql b/csharp/ql/test/library-tests/csharp11/nativeInt.ql new file mode 100644 index 00000000000..c865833a452 --- /dev/null +++ b/csharp/ql/test/library-tests/csharp11/nativeInt.ql @@ -0,0 +1,12 @@ +import csharp +import semmle.code.csharp.commons.QualifiedName + +from LocalVariable v1, LocalVariable v2, Type t, string qualifier, string name +where + v1.getFile().getStem() = "NativeInt" and + v2.getFile().getStem() = "NativeInt" and + t = v1.getType() and + t = v2.getType() and + t.hasQualifiedName(qualifier, name) and + v1 != v2 +select v1, v2, getQualifiedName(qualifier, name)