# Deprecated functions with VS 2005

#1

So the project file for the Jucer is for Visual Studio 2005. That’s fine; I’d been meaning to upgrade anyhow.

However, building JUCE with VS 2005 yields 15 compiler warnings about deprecated functions in the run-time library. The deprecated functions are all ones that could potentially cause buffer overflows and there are replacement functions that don’t have that problem.

The problem is that the replacement functions aren’t cross-platform. Some of them are inside JUCE_WIN32 blocks anyhow, so that’s no big deal. Other ones aren’t.

There is a preprocessor macro that can be set to not show the warnings about deprecated functions. I could just turn that on.

However, it does seem to me that the code is better with the new functions. It makes the code less clean 'cos you have to litter it with more #ifdef JUCE_WIN32 lines, but that’s not too bad.

The other snag is that I don’t think the newer, more secure functions are available in the older Microsoft libraries. I guess we’d have to check and see if they’re in the new Platform SDK.

Unless someone’s got a better solution to all this?

Matt

#2

I will provide a VC6 jucer project in the next release, just didn’t have time to do one yet.

I don’t get any warnings in vcexpress (I don’t have vc2005 to try), but maybe I’ll see if I can find some kind of switch to turn on so I can see what the warnings are.

#3

I think the new secure functions are only available in VC 2005.

I can post the diffs if you like.

Matt

#4

Sure, that’d be interesting.

#5

This has turned out to be non-trivial. I’m still working on it; it might make more sense for me to put up a zip archive somewhere with some suggested changes.

Matt

#6

I’d be keen just to see the list of warning messages, if you could post that?

#7

i have this:

..\..\..\src\juce_core\io\juce_OutputStream.cpp(141) : warning C4996: '_vsnprintf' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdio.h(339) : see declaration of '_vsnprintf'
Message: 'This function or variable may be unsafe. Consider using _vsnprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

..\..\..\src\juce_core\basics\juce_Time.cpp(153) : warning C4996: '_ftime64' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\sys/timeb.h(152) : see declaration of '_ftime64'
Message: 'This function or variable may be unsafe. Consider using _ftime64_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\basics\juce_Time.cpp(402) : warning C4996: '__tzname' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\time.h(156) : see declaration of '__tzname'
Message: 'This function or variable may be unsafe. Consider using _get_tzname instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

..\..\..\src\juce_appframework\gui\graphics\contexts\juce_LowLevelGraphicsPostScriptRenderer.cpp(554) : warning C4996: 'sprintf' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdio.h(345) : see declaration of 'sprintf'
Message: 'This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

..\..\..\src\juce_core\text\juce_XmlElement.cpp(688) : warning C4996: '_snwprintf' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdio.h(450) : see declaration of '_snwprintf'
Message: 'This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

..\..\..\src\juce_core\text\juce_String.cpp(327) : warning C4996: 'mbstowcs' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdlib.h(527) : see declaration of 'mbstowcs'
Message: 'This function or variable may be unsafe. Consider using mbstowcs_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\text\juce_String.cpp(372) : warning C4996: 'mbstowcs' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdlib.h(527) : see declaration of 'mbstowcs'
Message: 'This function or variable may be unsafe. Consider using mbstowcs_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\text\juce_String.cpp(512) : warning C4996: '_snwprintf' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdio.h(450) : see declaration of '_snwprintf'
Message: 'This function or variable may be unsafe. Consider using _snwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\text\juce_String.cpp(583) : warning C4996: 'wcstombs' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdlib.h(562) : see declaration of 'wcstombs'
Message: 'This function or variable may be unsafe. Consider using wcstombs_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\text\juce_String.cpp(623) : warning C4996: 'wcstombs' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdlib.h(562) : see declaration of 'wcstombs'
Message: 'This function or variable may be unsafe. Consider using wcstombs_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\text\juce_String.cpp(1367) : warning C4996: '_vsnwprintf' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\stdio.h(450) : see declaration of '_vsnwprintf'
Message: 'This function or variable may be unsafe. Consider using _vsnwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\text\juce_String.cpp(1408) : warning C4996: 'wcscat' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\string.h(243) : see declaration of 'wcscat'
Message: 'This function or variable may be unsafe. Consider using wcscat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\text\juce_String.cpp(1593) : warning C4996: '_wcsupr' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\string.h(302) : see declaration of '_wcsupr'
Message: 'This function or variable may be unsafe. Consider using _wcsupr_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
..\..\..\src\juce_core\text\juce_String.cpp(1601) : warning C4996: '_wcslwr' was declared deprecated
C:\Programmi\Microsoft Visual Studio 8\VC\include\string.h(296) : see declaration of '_wcslwr'
Message: 'This function or variable may be unsafe. Consider using _wcslwr_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

#8

Ok, well none of those are actually risky at all, because they’re all used inside the string class, so it’d be safe just to turn off the warnings. But if I get chance, I’ll go through and try to fix them in a nicer way.

#9

You could always just declare _CRT_SECURE_NO_DEPRECATE in the juce files that those are used in since you use them in a safe way anyways.

#10

I’ve actually gone through version 1.33 and gotten the library to compile without warnings.

I realize that we could just use the #define to ignore the warnings, but I think it’s preferable to use the secure functions.

Jules - I could email you the changes or post them somewhere to download if you’d like to see what I did. I think I touched 8 files or so; most of them were small changes. The only real changes were in juce_String and juce_Time.

The nifty part is that the current version of JUCE is very close to being 64-bit ready; it’s not quite there, but could be without too much effort. It’s mostly a question of replacing all the inline assembly with compiler intrinsics.

Matt

#11

But not everyone has those ‘secure’ functions.

#12

Right; it’s all #ifdef’ed for the new compiler. Should still work for other compilers and platforms.

#13

Cool - well if you want to send me the changes, I’ll take a look. Cheers!

#14

You could just use Juce versions of those functions, like a Juce_sprintf which would be nothing but a define that links to whichever is needed for the compiler. It would also allow the user’s of juce to use them so they don’t have to worry/care about those either should they ever need them.

#15

I actually #define’d juce_sprintf differently if it’s the new Microsoft compiler; that seemed to be a nice, transparent way to do it. Doing that alone took care of quite a few of the warnings.

The changes I’m suggesting are pretty minimal. It’s up to Jules; after all this is his baby. I’ll post a download link here once I’ve tested my edits with the new compiler and the old one.

Matt

#16

Here’s my suggested changes for the 2005 Microsoft compiler:

The zip file only contains the files that have changed, with the JUCE source directory structure preserved. It’s based on the 1.34 release.

I’ve tested these changes with Visual C++ Express 2005, Visual Studio 2003 .NET, and Xcode 2.3, with JUCE built for Unicode and non-Unicode Strings on all three compilers.

If anyone wants to try this out, Visual C++ Express 2005 supports the new CRT functions and is free to download and use.

I did run into one very minor issue - Microsoft changed the way the time zone functions work, at least as far back as VS 2003. The code for Time::getTimeZone appears to be expecting a three-letter code for the time zone, but now instead of “PST” you get “Pacific Standard Time”, whether you use the old __tzname or the new _get_tzname function. This means you get “Pac” back from Time::getTimeZone.

Not a big deal, but it seemed worth mentioning.

Matt

#17