Re: pointer bug

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: David Browne (meat_at_hotmail.com)
Date: 03/07/04


Date: Sat, 6 Mar 2004 23:52:03 -0600


"agro_r" <agro_rachmatullah@yahoo-dot-com.no-spam.invalid> wrote in message
news:404aa796$1_2@Usenet.com...
> I think I've found a bug on Microsoft Visual C# or maybe on the .NET
> Framework itself... Look at this code:
>
> using System;
>
> public class Bar
> {
> public static void Main()
> {
> int[] a = {5, 4, 3, 2, 1};
> unsafe
> {
> fixed(int* ptr = a)
> {
> int* reader = ptr;
> while(true)
> {
> Console.Write("@ 0xX{0:X}is ", (uint)reader);
> Console.WriteLine("{0}", *(reader--));
> }
> }
> }
> }
> }
>

unsafe code isn't guaranteed to throw an exception when you do bad things.
That's why it's unsafe.

Once you dereference reader-1, all bets are off.

David



Relevant Pages

  • Re: Is *all* thread cached data flushed at MemoryBarrier
    ... another framework version or hardware platform. ... but as I understand it the x86 memory model only ... doesn't make any guarentees about reads. ... example is unsafe. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH 2/2] tracing: identify which executable object the userspace address belongs to
    ... it's generally unsafe to look up a vma and use it without having ... Bug: it is unsafe to look up a task and then drop the RCU lock and use ...
    (Linux-Kernel)
  • Re: C# Unsafe Bug
    ... I am pasting a console application below. ... I don't believe this is a bug, and I don't believe it has anything to ... do with unsafe code. ...
    (microsoft.public.dotnet.languages.csharp)
  • C# Unsafe Bug
    ... I was writing some routines which could do bitwise boolean operations ... on byte arrays, and I ran into what I think is a bug with C#'s unsafe ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Total order on floating point numbers
    ... which is why it was unsafe to use on system files ... that sort of reason. ... as I haven't used it since I discovered that bug. ...
    (comp.arch.arithmetic)