Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3274160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:00:29+00:00 2026-05-17T19:00:29+00:00

My program is crash intermittently when it tries to copy a character array which

  • 0

My program is crash intermittently when it tries to copy a character array which is not ended by a NULL terminator(‘\0’).

class CMenuButton {
   TCHAR m_szNode[32];
   CMenuButton() {
     memset(m_szNode, '\0', sizeof(m_szNode));
   }
};
int main() {
  ....
  CString szTemp = ((CMenuButton*)pButton)->m_szNode; // sometime it crashes here
  ...
  return 0;
}

I suspected someone had not copied the character well ended by ‘\0’, and it ended like:

            Stack
m_szNode    $%#^&!&!&!*@*#&!(*@(!*@@&#&*&@@!^&*&#(*!@*((*&*SDFKJSHDF*(&(*&(()(**

Can you tell me what is happening and what should i do to prevent the copying of wild pointer? Help will be very much appreciated!

I guess I’m unable to check if the character array is NULL before copying…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:00:30+00:00Added an answer on May 17, 2026 at 7:00 pm

    I suspect that your real problem could be that pButton is a bad pointer, so check that out first.

    The only way to be 100% sure that a pointer is correct, and points to a correctly sized/allocated object is to never use pointers you didn’t create, and never accept/return pointers. You would use cookies, instead, and look up your pointer in some sort of cookie -> pointer lookup (such as a hash table). Basically, don’t trust user input.

    If you are more concerned with finding bugs, and less about 100% safety against things like buffer overrun attacks, etc. then you can take a less aggressive approach. In your function signatures, where you currently take pointers to arrays, add a size parameter. E.g.:

    void someFunction(char* someString);
    

    Becomes

    void someFunction(char* someString, size_t size_of_buffer);
    

    Also, force the termination of arrays/strings in your functions. If you hit the end, and it isn’t null-terminated, truncate it.

    Make it so you can provide the size of the buffer when you call these, rather than calling strlen (or equivalent) on all your arrays before you call them.

    This is similar to the approach taken by the “safe string functions” that were created by Microsoft (some of which were proposed for standardization). Not sure if this is the perfect link, but you can google for additional links:

    http://msdn.microsoft.com/en-us/library/ff565508(VS.85).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does the following program crash? I have a base class whose destructor is
I have had some problems earlier which caused my program to crash in all
Working on a class assignment in C#, I came across a program crash without
My multithread program crash. I have .core file. I load it and thread apply
For some reason the following doesn't crash like my program does, but I'm pretty
What would be the best way to handle lightweight crash recovery for my program?
I am calling a command-line program from my Perl script. When these programs crash,
Does anyone have any idea why the following causes the program to crash? NSFileManager
Can any body tells me what are the reasons of program crash when somebody
An application in the field is getting this message intermittently: I am not able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.