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. Buffer Overrun

Buffer Overrun

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 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.
  • L Offline
    L Offline
    LCI
    wrote on last edited by
    #1

    I have a buffer overrun problem that i am not 100% sure of the best way to fix it. If someone can give me some direction i would appreciate it. I have the following : Two structs with fields of different values that i am attempting to StrCpy(); typedef struct _myInfo { TCHAR szOwnerLastName[64]; TCHAR szOwnerFirstName[64]; } MyInfo; typedef struct _otherInfo { TCHAR szOwnerLastName[32]; TCHAR szOwnerFirstName[32]; } OtherInfo; MyInfo* pMyInfo; OtherInfo* pOtherInfo; After populating these fields, here is what i find: If i do a : StrCpy(pOtherInfo->szOwnerLastName, pMyInfo->szOwnerLastName); Since MyInfo is bigger than OtherInfo, the above statement basically writes into the OtherInfo's Firstname field. Is there a nice way to get around this? I cannot change the field sizes for either structure. Thanks, cw

    D S 2 Replies Last reply
    0
    • L LCI

      I have a buffer overrun problem that i am not 100% sure of the best way to fix it. If someone can give me some direction i would appreciate it. I have the following : Two structs with fields of different values that i am attempting to StrCpy(); typedef struct _myInfo { TCHAR szOwnerLastName[64]; TCHAR szOwnerFirstName[64]; } MyInfo; typedef struct _otherInfo { TCHAR szOwnerLastName[32]; TCHAR szOwnerFirstName[32]; } OtherInfo; MyInfo* pMyInfo; OtherInfo* pOtherInfo; After populating these fields, here is what i find: If i do a : StrCpy(pOtherInfo->szOwnerLastName, pMyInfo->szOwnerLastName); Since MyInfo is bigger than OtherInfo, the above statement basically writes into the OtherInfo's Firstname field. Is there a nice way to get around this? I cannot change the field sizes for either structure. Thanks, cw

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      LCI wrote:

      Is there a nice way to get around this?

      Yes, use strncpy() instead. Or use std::string and not worry about it.


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      1 Reply Last reply
      0
      • L LCI

        I have a buffer overrun problem that i am not 100% sure of the best way to fix it. If someone can give me some direction i would appreciate it. I have the following : Two structs with fields of different values that i am attempting to StrCpy(); typedef struct _myInfo { TCHAR szOwnerLastName[64]; TCHAR szOwnerFirstName[64]; } MyInfo; typedef struct _otherInfo { TCHAR szOwnerLastName[32]; TCHAR szOwnerFirstName[32]; } OtherInfo; MyInfo* pMyInfo; OtherInfo* pOtherInfo; After populating these fields, here is what i find: If i do a : StrCpy(pOtherInfo->szOwnerLastName, pMyInfo->szOwnerLastName); Since MyInfo is bigger than OtherInfo, the above statement basically writes into the OtherInfo's Firstname field. Is there a nice way to get around this? I cannot change the field sizes for either structure. Thanks, cw

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        Do you have to use raw strings? Why not use std::string or some other string class? What should happen to the bit of the string that can't fit in the smaller buffer?

        Steve

        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