CSharp/C# >> pointer bug

by agro_rachmatullah » Sun, 07 Mar 2004 12:39:50 GMT

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--));
}
}
}
}
}

This code didn't throw an exception (which I expected), but the
program just terminates... Curiously, if we use "int a" instead of
"int[] a" and modify the rest of the program accordingly, the program
will indeed throw an exception. Does anyone know how I can contant
the .NET/C# team about this problem?


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


CSharp/C# >> pointer bug

by David Browne » Sun, 07 Mar 2004 13:52:03 GMT





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




CSharp/C# >> re:pointer bug

by agro_rachmatullah » Sun, 07 Mar 2004 21:41:46 GMT

I assumed that when we play with unsafe code and do something really
bad, an exception will be thrown.

I still find it inconsistent that on some occurence it throws an
exception, and on some occurence it just quits.


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Similar Threads

1. Template specialization to pointers - bug or what?

2. Bug in VC8 - assignment of raw pointer to auto_ptr compiles then crashes when run

Is this a known bug?

Under VC7.1 this code fails to compile

#include "stdafx.h"
#include <memory>
using namespace std;

struct X
{
int mVal;
};

int _tmain(int argc, _TCHAR* argv[])
{
auto_ptr<X> xPtr;
xPtr = new X;
return 0;
}

but under VC8 it compiles and then crashes.

This is very nasty, especially if you happen to be converting old code using 
raw pointers to auto_ptrs.
I am going to switch to boost::scoped_ptr, where possible.

The problem seems to be that auto_ptr_ref now has a ctor taking a void * 
whereas before it took an auto_ptr<_Ty>&.


Kit 


3. VC6's bug on casting multi-array to pointer

4. Bug: __gc pointer in delegate declaration causes error message

Dear VC++ team,

I am fairly certain I found a bug in VC++ 7.1.

I get the following error

========================================================================

Microsoft (R) C/C++ Standard Compiler Version 13.10.3077 for .NET Framework
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

test.cpp
test.cpp(3) : error C2653: 'xSystem' : is not a class or namespace name
test.cpp(3) : error C2143: syntax error : missing ',' before '*'

========================================================================

when I compile the following code:

==== Begin test.cpp ====================================================

#using <mscorlib.dll>

public __delegate void Test(int __gc * x, int * y);

int main() { return 0; }

==== End test.cpp ======================================================

using the following command line:

cl /clr test.cpp

which indicates some kind of buffer overflow or something, since the 
name "xSystem" does not occur anywhere in the code.

Greetings

Bart Jacobs

5. Compiler template bug in VC++ 7.1 with pointer to members

6. BUG: sort list of pointers VC++ 6.0 template

To sort a list of pointers supplying a predicate function other than
"greater<>" requires changing the <list> template file as follows:

/*
in <list>

1) comment out the typedef and add "template>class _Pr3>" right before "void
merge(_Myt& _X, _Pr3 _Pr)"

//typedef greater<_Ty> _Pr3;
template<class _Pr3>

2) before "sort(_Pr3 _Pr)" add "template<class _Pr3>"

template<class _Pr3>
void sort(_Pr3 _Pr)

This is Microsoft VC++ 6 bug
Without this change you will get a C2664 error on the sort call because it
cannot convert greaterThanIt to a greater<_Ty>
*/


struct greaterThanIt : std::binary_function<CFeature const *, CFeature const
*, bool>
{
bool operator()(CFeature const * x, CFeature const * y) const
{ return x->GetLeft() < y->GetLeft(); }
};

/** sort the FeatureList left to right, which is a list made up of CFeature
pointers,*/
void CFeatureList::sortFeature()
{
sort( greaterThanIt());
}

- rich


7. BUG: template pointer to function (full message)

8. BUG: template pointer to function

Hi to all,

    I've come across this bug in VC7.1
rpn_c is a wrapper for pointers to functions taking several arguments




template <typename function_t>
struct rpn_c;


template <typename T>
struct rpn_c< T (*)(const T&, const T&) >
{
 typedef T (*f_t)(const T&, const T&);

 template <f_t F>
  static T eval(const T* x)
 {
  return F(x[0],x[1]);
 }

};




int ran2(const int&,const int&)
{
 return 5;
}



int main()
{
 int a[2] = {4, 5};
 int* aa =a;

 typedef int (*ifunc)(const int&,const int&);

// runtime assignemnt succeeds
 rpn_c<ifunc>::f_t F = ran2;

// compile-time evaluation does not work
 int i = rpn_c<ifunc>::eval<ran2>(aa);

 return 0;
}













-- 
 A problem is a problem is a problem
 A solution is a solution.
-- Mycroft Holmes