Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Detecting out-of-bounds in dynamic array?

Detecting out-of-bounds in dynamic array?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestionc++performance
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dontknowitall
    wrote on last edited by
    #1

    How do I enable out-of-bounds memory checking for dynamically allocated memory (new/delete) in VC++ 2003? /RTC options enable stack-based checks, which I've got turned on, but that doesn't cover heap-based allocations.

    CPalliniC M 2 Replies Last reply
    0
    • D dontknowitall

      How do I enable out-of-bounds memory checking for dynamically allocated memory (new/delete) in VC++ 2003? /RTC options enable stack-based checks, which I've got turned on, but that doesn't cover heap-based allocations.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Simply you cannot (AFAIK). :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      In testa che avete, signor di Ceprano?

      D 1 Reply Last reply
      0
      • CPalliniC CPallini

        Simply you cannot (AFAIK). :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        D Offline
        D Offline
        dontknowitall
        wrote on last edited by
        #3

        Well, I was hoping for a configurable option. Overloading operator new and delete is my backup plan, which will work because I only use new/delete.

        CPalliniC 1 Reply Last reply
        0
        • D dontknowitall

          Well, I was hoping for a configurable option. Overloading operator new and delete is my backup plan, which will work because I only use new/delete.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Can you do that?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          In testa che avete, signor di Ceprano?

          D 1 Reply Last reply
          0
          • CPalliniC CPallini

            Can you do that?

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            D Offline
            D Offline
            dontknowitall
            wrote on last edited by
            #5

            Of course. Overloading new/delete is part of the C++ Standard. Just tack on some extra bytes (on either side) during allocation and check those bytes before deleting the memory. If a match fails, then something overwrote the memory. Poor-man's solution is to use TRACE() at that point. A stack dump would be nicer. Even better would be the compiler offering the option at compile-time to do all of that without writing any code.

            CPalliniC 1 Reply Last reply
            0
            • D dontknowitall

              Of course. Overloading new/delete is part of the C++ Standard. Just tack on some extra bytes (on either side) during allocation and check those bytes before deleting the memory. If a match fails, then something overwrote the memory. Poor-man's solution is to use TRACE() at that point. A stack dump would be nicer. Even better would be the compiler offering the option at compile-time to do all of that without writing any code.

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              I didn't know that. thank you. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • D dontknowitall

                How do I enable out-of-bounds memory checking for dynamically allocated memory (new/delete) in VC++ 2003? /RTC options enable stack-based checks, which I've got turned on, but that doesn't cover heap-based allocations.

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                The debug CRT does it for you (using sentry bytes I believe). Try this in a debug build: BYTE *pBytes = new BYTE[10]; pBytes[10] = 255; delete[] pBytes;

                "If you can dodge a wrench, you can dodge a ball."

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups