Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2008-05-02 22:24:59 +0400
committerMarek Safar <marek.safar@gmail.com>2008-05-02 22:24:59 +0400
commite81e477dfcf85a598f20e990a03623f9788c7bb6 (patch)
tree8e7fd09479bc6774a8c6223a0d4925cc3eea8fd9 /mcs/tests/test-643.cs
parentbfb7c5e06ab532dbfe44a71804ee82c3fae2bf42 (diff)
New test.
svn path=/trunk/mcs/; revision=102362
Diffstat (limited to 'mcs/tests/test-643.cs')
-rw-r--r--mcs/tests/test-643.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/mcs/tests/test-643.cs b/mcs/tests/test-643.cs
new file mode 100644
index 00000000000..b8f6f16cf10
--- /dev/null
+++ b/mcs/tests/test-643.cs
@@ -0,0 +1,55 @@
+// Compiler options: -unsafe
+
+using System;
+
+class PointerArithmeticTest
+{
+ unsafe static int Main()
+ {
+ try {
+ return CheckAdd((byte*)(-1), -1);
+ } catch (System.OverflowException) {}
+
+ try {
+ return CheckSub((short*)(-1), int.MaxValue);
+ } catch (System.OverflowException) {}
+
+ CheckSub2((short*)(-1), int.MaxValue);
+
+ if ((long)Conversions (long.MaxValue) != uint.MaxValue)
+ return 5;
+
+ Console.WriteLine ("OK");
+ return 0;
+ }
+
+ unsafe static int* Conversions (long b)
+ {
+ return (int*)b;
+ }
+
+ unsafe static int CheckAdd(byte* ptr, int offset)
+ {
+ if (checked(ptr + offset < ptr))
+ return 1;
+
+ return 101;
+ }
+
+ unsafe static int CheckSub(short* ptr, int offset)
+ {
+ if (checked(ptr - offset < ptr))
+ return 2;
+
+ return 102;
+ }
+
+ unsafe static int CheckSub2(short* ptr, int offset)
+ {
+ short* b = ptr + offset;
+ if (checked(ptr - b < 0))
+ return 3;
+
+ return 0;
+ }
+}