"Richard" <rgrdev@gmail.com> a écrit dans le message de news:
56uht4-gb6.ln1@news.individual.net...
> "Charlie Gordon" <news@chqrlie.org> writes:
>
>> "Richard" <rgrdev@gmail.com> a écrit dans le message de news:
>> ftaft4-tni.ln1@news.individual.net...
>>> santosh <santosh.k83@gmail.com> writes:
>>>
>>>> Joe Mayo wrote:
>>>>
>>>>> jacob navia schrieb:
>>>>>> ...
>>>>>> No abstraction, low level, dangerous procedures like strncpy
>>>>> > ...
>>>>>
>>>>> What is dangerous on strncpy?
>>>>> Is strcpy not much more dangerous than strncpy?
>>>>
>>>> Both are dangerous only when misused. In addition strncpy has a
>>>> possibly
>>>> misleading name, which is really what , I suspect, jacob was referring
>>>> to.
>>>
>>> The reply above is valid for ANY form of C programming.
>>>
>>> i=i++
>>>
>>> can be potentially lethal too if you dont know what you are doing.
>>>
>>> For gods sake, leave strncpy alone. It does what it is documented to do.
>>>
>>> strtok and gets are the ones to diss.
>>
>> strtok and gets also do what they are documented to do, yet you agree
>> they
>> should be deprecated.
>
> I dont agree any suhc thing. But they are fatally flawed.
>
>> strncpy is so easy to misuse and so widely misused that it should be more
>> actively scrutinized.
>
> You are either a very bad programmer or a troll. Sorry but strncpy does
> what the documentation says. The fact that you seem unwilling or
> incapable of using it correctly has become a tad boring to be honest.
These are false accusations: I know perfectly well what strncpy does and am
quite capable of using it correctly. In my projects, I have never seen a
single place where its semantics were appropriate. strncpy has never been
"the right thing", contrary to strlcpy. My "boring" persistence at warning
other programmers about strncpy is a pedagogical move : so many "savvy"
regulars on c.l.c seem unable to grasp the concept of "error prone" and "too
easy to misuse".
>> A compiler warning seems appropriate for all of them.
>
> Bullshit. Would you like a compiler warning when incrementing a pointer
> too in case the programmer forgets to keep it pointing to valid memory?
If the compiler can determine that the pointer is incremented beyond the
border of the array, a warning seems appropriate to me. I the pointer is
known to be NULL, a warning is definitely useful:
char *p = NULL;
char *q = p++; /* please tell me this is bogus! */
--
Chqrlie.