Douglas Leder is right. There is a limit to the usefulness of replacing strcpy if you do not want to do work with coarse transfers in a good, reasonable buffer length in each instance. This is a lot of work!
The good news is worth it! A few years ago, I came up with several C ++ projects that were late, erroneous, and unreliable. By declaring strcpy and strlen forbidden, and taking 2-3 days from the project to replace them with custom strncpy / strnlen, we could suddenly work in all of these projects for several days, not hours. We also saw that a lot of truncated lines appeared on screens and log files. This gave us the hints needed to track truncation problems, previously encountered problems.
If you do not want to do this, you can get much less benefit by simply checking both pointer options for NULL and limiting the maximum size of the string copy and registering all the time the border is reached. Do not run strlen on any of the parameters, as strlen will happily crash on you if the line is not terminated by zero correctly.
New projects currently use good string objects, but there is a lot of legacy code that doesn't.
kmarsh
source share