Menu

Pointer to 0xffffffff

2004-09-23
2012-09-26
  • Nobody/Anonymous

    Hi :)

    Is there any way to prevent access errors on pointers like 0xffffffff or 0xbaadf00d ... ? I'm looking for something like a try/catch block ?

    Thanks

    Paul.

     
    • Nobody/Anonymous

      there are many utilites codes out there that use modified new/delete and smart pointers to do what you are asking. i suggest boost simply because it has something to do virtually everything.

      there is no simply way of checking bad points. if you only wanted to check obviously bad pointers like 0 you could do that yourself. if you mean situations like possibly getting memory from new and later deleting, or having someone using your api not delete it, or going past the memory allocated by new then you are stuck writting code or using utilites.

      the general idea is to check whether or not your new currently "owns" the memory at where the pointer points to.

      aside from all that. it is better to write code that does not need this. do bounds checking use smart pointers that only delete themselves when the reference count reaches zero and write classes in such a way there are always in a valid state. that is no public data.

      obag

       
    • Anonymous

      Anonymous - 2004-09-23

      C/C++ only checks for NULL (zero) pointer dereferencing. It assumes all non-zero pointers are valid. More sophisticated checking is not built into the language - follow Kip and obag's suggestions.

      Clifford

       
    • Nobody/Anonymous

      Cliff / Obag, can you tell me more about pointer dereferencing?

      Kip

       
      • Anonymous

        Anonymous - 2004-09-24

        I sense I am being had, but if it helps:

        dereferencing: accessing the object pointed to by a pointer. It the pointer is zero, the runtime can detect it as an error.

        Clifford

         
    • aditsu

      aditsu - 2004-09-24

      I think what Paul wants is something like SEH: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/structured_exception_handling.asp
      last time I checked, MinGW didn't support it

      Adrian

       
    • Nobody/Anonymous

      Thanks for you answers.
      The problem is that I don't want do delete the objects the pointers point to. When I use an object corresponding to a pointer, I set it to NULL in order not to touch the object any more (via this list of pointers - I reuse the objects via another list). So, when I modify these pointers, I just set it to NULL ; if I don't modify them, they correctly point to the corresponding objects (I display the list). I never delete one of these pointers, that's why I'm astonished...

      Paul

       
    • Kip

      Kip - 2004-09-24

      Woops, sorry, I asked the wrong question. I meant smart pointers =)

      Kip

       
    • Nobody/Anonymous

      You can check for a bad pointer before using the pointer with IsBadCodePtr, IsBadHugeReadPtr, IsBadHugeWritePtr, IsBadReadPtr, IsBadStringPtr, and IsBadWritePtr functions.

      Otherwise, you can check for a bad pointer when accessed by writing your own exception handler. Once installed, it will be invoked when the OS throws a SIGSEGV (segment fault violation). You can use exception records and the various other structures provided to see where the fault was triggered, why, and more details such as what was accessed.

      Kip

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.