You have taken a box with exactly enough room for 10 eggs and tried to jam 11 eggs into it. What does that get you? Not doing this is your responsibility and the compiler will generally not detect such things. I do not know your motivation for using strcpy, but if you use std::string instead of C style strings, you will get boxes that expand to accommodate what you stuff in them.
These should fix it. Collectives on Stack Overflow. Learn more. Why is strcpy unsafe in C? Asked 7 years, 6 months ago. Active 7 years, 6 months ago. Viewed 24k times. Improve this question. MechAvia MechAvia 1 1 gold badge 4 4 silver badges 11 11 bronze badges. Actually, things get interesting when the MSVC compiler tells you that strncpy is also unsafe. Where is the support for the c99 standard? Yeah, Microsoft wants to embrace, extend, extinguish C as well.
Unfortunately, a lot of programmers don't code well, and then demand a "safer" language. Suggest: char str2[sizeofstr1]; and avoid magic numbers like I press continue and following appears:. I don't know what the function's orientation is. Learn More. Ask a question. Quick access. Search related threads.
Remove From My Forums. Answered by:. First, it is important to say that you can safely use this function. Her problem is that the programmer may forget or not know how to do this.
The first problem with the function is that it does not consider the size of what it is copying, so it is possible to overwrite an area of memory that was not intended.
Usually the memory is allocated where the string copy is placed and then the operation is performed.
0コメント