473,836 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strncpy_s and gcc ?

I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated

It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.

However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?

2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)

Oct 17 '06 #1
11 18590

tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated

It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.

However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?

2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
Frankly, no-one cares what MS thinks. Copying an object, like a string,
should be handled by a copy constructor, period. When you hear MS say
the word "string", that can mean a lot of different things.

#include <string>

int main()
{
std::string s("a short string");
std::string copy(s); // and that's how you copy a string - copy ctor
- simplicity defined
}

Oct 17 '06 #2

Salt_Peter skrev:
tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated

It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.

However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?

2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)

Frankly, no-one cares what MS thinks. Copying an object, like a string,
should be handled by a copy constructor, period. When you hear MS say
the word "string", that can mean a lot of different things.

#include <string>

int main()
{
std::string s("a short string");
std::string copy(s); // and that's how you copy a string - copy ctor
- simplicity defined
}
You are right - this is the way it should be, but unfortunately it does
not answer my question on status on strncpy_s.

The situation is that I have a lot of old code with old char*-strings.
Now when I compile VS says something and gcc says something else.

What is the truth about it ?
So the question remains ....
(But thanks for your input)

Oct 17 '06 #3
tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated

It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.

However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
There is no strncpy_s in the current standard. I also didn't find it in the
TR1 draft.
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
The gcc mailing lists would be a good place for this question.
Best

Kai-Uwe Bux
Oct 17 '06 #4
On 17 Oct 2006 01:25:32 -0700, "tmartsum" <tm******@gmail .comwrote:
>I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated
Those functions shall make the notoriously error-prone C string
functions a little safer.
>It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
IIRC, there are ongoing activities to standardize those functions.
>2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
Maybe you'll find a free implementation?

Best wishes,
Roland Pibinger
Oct 17 '06 #5

tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated

It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.
Right. It isn't deprecated by C or C++. But since this is clc++, I'll
ignore ISO C.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
I think it was (part of) a proposal at some time, for the C++0x
release. It's
not in TR1, though.
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
Correct, but really off-topic here. ISO C++ doesn't have strncpy_s.

The level of verbosity typically depends on the exact compiler
settings. ISO
allows any warning, as long as legal C++ code still works. This
particular
warning can be turned off just with a setting, too. This would be the
best
approach if you desire portable code.

HTH,
Michiel Salters

Oct 17 '06 #6

Mi************* @tomtom.com skrev:
tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated

It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.

Right. It isn't deprecated by C or C++. But since this is clc++, I'll
ignore ISO C.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?

I think it was (part of) a proposal at some time, for the C++0x
release. It's
not in TR1, though.
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct

Correct, but really off-topic here. ISO C++ doesn't have strncpy_s.

The level of verbosity typically depends on the exact compiler
settings. ISO
allows any warning, as long as legal C++ code still works. This
particular
warning can be turned off just with a setting, too. This would be the
best
approach if you desire portable code.

HTH,
Michiel Salters
ISO allows any warning, as long as legal C++ code still works.

OK - so MS is allowed to give any warning - I am however not happy with
warnings that suggest me to change my code into something that is not
(ISO) c++...

Oct 17 '06 #7
"tmartsum" <tm******@gmail .comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
>
Mi************* @tomtom.com skrev:
>tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated

It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.

Right. It isn't deprecated by C or C++. But since this is clc++, I'll
ignore ISO C.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?

I think it was (part of) a proposal at some time, for the C++0x
release. It's
not in TR1, though.
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct

Correct, but really off-topic here. ISO C++ doesn't have strncpy_s.

The level of verbosity typically depends on the exact compiler
settings. ISO
allows any warning, as long as legal C++ code still works. This
particular
warning can be turned off just with a setting, too. This would be the
best
approach if you desire portable code.

HTH,
Michiel Salters

ISO allows any warning, as long as legal C++ code still works.

OK - so MS is allowed to give any warning - I am however not happy with
warnings that suggest me to change my code into something that is not
(ISO) c++...
That's Microsoft for you. And it should be _strncpy_s since it's an
extension. Microsoft did that from some calls from VC6 to VC .net 2003,
but on this one I think they thought it would be in the new standard or
something.
Oct 17 '06 #8
Salt_Peter wrote:
Frankly, no-one cares what MS thinks.
Well, the chair of the ISO C++ commitee is from Microsoft, and there's
only like eleventy billion lines of code written for MS platforms.
Perhaps MS does have something to say after all.

Regards,
Bart.

Oct 17 '06 #9

tmartsum wrote:
Salt_Peter skrev:
tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated
>
It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.
>
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
>
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
Frankly, no-one cares what MS thinks. Copying an object, like a string,
should be handled by a copy constructor, period. When you hear MS say
the word "string", that can mean a lot of different things.

#include <string>

int main()
{
std::string s("a short string");
std::string copy(s); // and that's how you copy a string - copy ctor
- simplicity defined
}

You are right - this is the way it should be, but unfortunately it does
not answer my question on status on strncpy_s.
The routine strncpy_s() and the other, related "_s"-suffixed Standard C
library routines are an ISO - and not a Microsoft - set of extensions.
Specifically the "bounds-checking" interfaces are a draft TR extension
to the standard C library. They will no doubt will eventually make
their way into the C and C++ Standards.

Nor would I recommend waiting before adopting bounds-checking routines
to replace their unsafe C library equivalents. After all, blind
adherernce to "standards" is no excuse for writing insecure programs.

For futher reading:

Status of various C Standard projects:

http://www.open-std.org/JTC1/SC22/WG...projects#24731

which includes a link to the latest Draft of the the bounds-checking C
Library extensions:

http://www.open-std.org/JTC1/SC22/WG...docs/n1146.pdf

Greg

Oct 18 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
11738
by: Matt Parkins | last post by:
Hi, (I realise this probably isn't precisely the right group for this - could someone direct me to the appropriate group to post this question? - thanks !) I'm using Visual C++ 2005 Express Edition Beta (free download from MS - hooray!), and everything works fine, except I get warnings back on the use of some functions, strlen() for example, saying that the function has been deprecated - although they do still work (which is I guess...
68
3743
by: Roman Ziak | last post by:
Hello, I just downloaded MS Visual Studio 2005 Express Beta. When I tried to compile existing valid project, I get a lot of warnings like 'sprintf' has been deprecated, 'strcpy' has been deprecated etc. I opened STDIO.H and figured that one has to define a macro _CRT_SECURE_NO_DEPRECATE to stop these warnings. I started to search internet and found few links, and the following proposal
7
16827
by: Olaf Baeyens | last post by:
I am testing VC++ 2005 and I get this warning: "warning C4996: 'strncpy' was declared deprecated" Does that mean that they might be phased out in VC++ 2006 or higher? Or does an alternative function exist as replacement?
62
4150
by: Juuso Hukkanen | last post by:
I am looking for a wish list of things which should be removed from the C (C99) - due to feature's bad security track record <OT>or Multithreading unsafety. I need this list for a project intending to build another (easiest & most powerful) programming language, which has a two page definition document stating: "... includes C programming language (C99), except its famous "avoid-using-this-functions". </OT> If you would not want to...
7
2028
by: jacob navia | last post by:
Microsoft proposed recently (In the Technical Report 24173 presented to the Standards Comitee) a change in the C library in the sense of more security. Basically, missing size information is passed to the new primitives like strcat_s(), gets_s(), and many others. The good thing in this proposal is that the specifications of the new library are much more precise than in the existing library, an improvement that made me start...
7
2101
by: AlanJSmith | last post by:
I am converting some C++ projects from 6 to vs2005 in one of the headers i have the code that follows this passage in which I get an error saying int default cant be assumed so i added DBString<nSizeDBString<nSize>:: to the copy assignment same size oporator and this seems to work, if i try the same thing with copy assignment different sizes i get error C3856: 'DBString<nSize>::=': class is not a class template and adding any type between...
11
2390
by: OmarOthman | last post by:
How does the MS Visual C++ 6.0 compiler deal with the following?! int main() { ... } I mean that there's no "return 0;". There's no int returned at all. How does this compile?! I'm a C# expert, and this never compiles on C#. Please explain your answer in terms of what the compiler assumes and what it does actually... Thanks in advance.
70
3651
by: junky_fellow | last post by:
Guys, If main() calls some function func() and that function returns the error (errno), then does it make sense to return that value (errno) from main. (in case main can't proceed further) ? eg. int main(void) {
0
1806
by: Dilip | last post by:
I have cross-posted this question to 3 newsgroups since I am not sure exactly where it belongs (and some NG's have very less activity). Apologies in advance for this. I have set the followup to the dotnet.framework.interop NG but feel free to chage it as appopriate. I have a question regarding converting a Managed System.String^ to unmanaged const char*. I inherited a code that does it like this: String^ s = "00000";
0
9813
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9665
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10835
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10585
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5818
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.