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. Found Api's Causing Heap Corruption

Found Api's Causing Heap Corruption

Scheduled Pinned Locked Moved C / C++ / MFC
json
8 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    These lines in My DrawItem Api are causing the heap corruption

    if(arrayptr[pdi->itemID] == NULL)
    arrayptr[pdi->itemID] = new char(9);
    memset(arrayptr[pdi->itemID], 0x00, 9);
    memcpy(arrayptr[pdi->itemID], lpszText, 8);

    Don't understand it as I allocated everything on the Heap

    CPalliniC 1 Reply Last reply
    0
    • F ForNow

      These lines in My DrawItem Api are causing the heap corruption

      if(arrayptr[pdi->itemID] == NULL)
      arrayptr[pdi->itemID] = new char(9);
      memset(arrayptr[pdi->itemID], 0x00, 9);
      memcpy(arrayptr[pdi->itemID], lpszText, 8);

      Don't understand it as I allocated everything on the Heap

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

      Quote:

      arrayptr[pdi->itemID] = new char(9);

      Should be

      arrayptr[pdi->itemID] = new char[9];

      In testa che avete, signor di Ceprano?

      F L 3 Replies Last reply
      0
      • CPalliniC CPallini

        Quote:

        arrayptr[pdi->itemID] = new char(9);

        Should be

        arrayptr[pdi->itemID] = new char[9];

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        WOW thanks good catch I didn't see however where the storage was initialized to 9 let me try thanks

        1 Reply Last reply
        0
        • CPalliniC CPallini

          Quote:

          arrayptr[pdi->itemID] = new char(9);

          Should be

          arrayptr[pdi->itemID] = new char[9];

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          thanks

          CPalliniC 1 Reply Last reply
          0
          • F ForNow

            thanks

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

            You are welcome. Did you really need to use raw (C-like) arrays and new?

            In testa che avete, signor di Ceprano?

            F 1 Reply Last reply
            0
            • CPalliniC CPallini

              You are welcome. Did you really need to use raw (C-like) arrays and new?

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #6

              I am MainFrame programmer by trade wasn't sure how to copy the first 8 characters of the 45 character strings Thanks

              1 Reply Last reply
              0
              • CPalliniC CPallini

                Quote:

                arrayptr[pdi->itemID] = new char(9);

                Should be

                arrayptr[pdi->itemID] = new char[9];

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I missed that twice in the original thread below. Well spotted.

                CPalliniC 1 Reply Last reply
                0
                • L Lost User

                  I missed that twice in the original thread below. Well spotted.

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

                  Thank you, Richard. :)

                  In testa che avete, signor di Ceprano?

                  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