Why is strdup() deprecated in VS 2005?
Why is strdup() deprecated in VS 2005?
This post has been edited either by the author or a moderator in the
Microsoft Forums: http://forums.microsoft.com You may not care about it, but I
do. I don't want to disable the warning because I think the concerns
with most of the deprecated functions are very valid, and only wished
Microsoft had done this a long time ago. As such, I have taken the
opportunity to change a lot of my code to use the new functions. The
problem is that I still call strdup(), stricmp(), and strnicmp(), which are
deprecated but have no obvious replacements. And now I am getting
warnings which I have no idea how to fix (besides disabling the warning, which
is not a fix IMHO).
These functions are not ANSI but Microsoft
specific, so they are now prefixed with _
like _strdup()
Willy.
Why is strdup() deprecated in VS 2005?
Athar.Iqbal
Andre.Ziegler
Curt Nichols
shameel
Paranth
if you're going to deprecate strcpy you might as well deprecate C
Roygar
Drum Red
CarlosMaxx
I can not imagine why strdup is unsafe, because it will just duplicate a string but AFAIK all string functions that are only \0 terminated are declared deprecated.
Just disable the warning with /wd4996 and its ok.
I do not really care about this...
ramdee
strdup() and stricmp() are now deprecated and have been replaced by _strdup() and _stricmp() respectively. So all I have to do to get rid of the compiler warning is to add an underscore in front of all of these calls. Thanks very much for your help!
Polypterus
<hyslopc@discussions.microsoft.com> wrote in message
news:25baebab-b388-4024-b75c-433b2d5c3a32_WBRev1_@discussions.microsoft.com
> Consider the following code:
>
> char * Dest = new char [ 6 ];
>
> strcpy(Dest, "Hello World");
>
> This (admittedly silly) example compiles fine but is guaranteed to
> corrupt the heap. Consider the new secure version:
>
> strcpy_s(Dest, sizeof(Dest), "Hello World");
> - this will result in Dest getting the value "Hello"
--
With best wishes,
Igor Tandetnik
elmoman
Dragon123456789
char * Dest = new char [ 6 ];
strcpy(Dest, "Hello World");
This (admittedly silly) example compiles fine but is guaranteed to corrupt the heap. Consider the new secure version:
strcpy_s(Dest, sizeof(Dest), "Hello World");
- this will result in Dest getting the value "Hello" and no heap corruption occurring. This is why strcpy() has been deprecated in favor of strcpy_s(), sprintf() has been deprecated in favor of sprintf_s(), etc.
strdup(), stricmp(), and strnicmp() have also been deprecated, and I assumed it was also related to security, but it's not. They are deprecated simply because they are not part of the ANCI C or C++ standard, and as such should always have been prefixed by an underscore. This was a historical mistake that Microsoft has now rectified in VS 2005.
Just as an aside, Microsoft has submitted all of the new ..._s() functions to the ANSI C++ committe for inclusion into the standard. Will be interesting to see how that goes.
NASWAY
dannyR