Correct on strcpy_s versus strncpy. Strncpy has the possibility of making a
new bad situation while preventing another. You can easily end up with a
string that is guaranteed to "run wild" if you strcpy it.

I *think* what I am going to do (with regard to the specifics of strcpy[_s])
is use either a function or a #define to build my own function that will
assert that the source string strlen is shorter than the target buffer. If
strlen seems to be a performance problem when the code moves into production
I could turn it off. One alternative would be strncpy plus a "just to be
sure" move of a zero into the last position of the output buffer.

sprintf_s is a little more problematic because without doing a full
"simulation" you don't know how long the result will be. OTOH, the results
are more predictable assuming you are not using %s and some string from the
outside world. So I think I will just #define sprintf_s so it uses sprintf
without checking. (Why use sprintf_s at all then? Because I am doing my
initial coding, syntax checking, and unit testing on (shudder!) MS Visual
Studio, where the _s functions are available. (Why? Sorry, but it's a much
more user-friendly and productive development environment than the big
iron.) I think there's a benefit to using them in some testing even if they
will not be available in all situations.

Charles

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:ibm-m...@bama.ua.edu] On Behalf
Of McKown, John
Sent: Friday, December 04, 2009 9:55 AM
To: IBM-MAIN@bama.ua.edu
Subject: Re: Is there a good mailing list or forum for mainframe C/C++
specifically?

All threads here get hijacked eventually. Some sooner than others. From
responses that __I__ have received from IBM in the past, they tend not to
implement "in flux" stuff. And, they basically say "give us a business case
to implement ... and we will prioritize it with other requests." What they
mean by "business case" is "how this will make us money" (reasonable). The
safe functions are not a standard. They are in a TR status. I don't really
know what that means. I am sure that once they become an ANSI/ISO standard,
IBM will implement them (eventually).

I had not realized that the safe functions have one major plus over the "n"
functions. They guarantee that the \0 can be copied too. And that the source
will fit in the dest area before doing anything at all. 

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@bama.ua.edu with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to