Path: csiph.com!news.samoylyk.net!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: Never use strncpy! Date: Thu, 22 Sep 2022 11:44:50 -0700 Organization: None to speak of Lines: 23 Message-ID: <87k05vdza5.fsf@nosuchdomain.example.com> References: <87o7v8zc4x.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="b6dd3111f3087e08fb468b174c9193d6"; logging-data="2402834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18x8KlqDTj3SIqh8WKdjzu1" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:CMklo9qcn/Gbu7WPqU4TRQSVWhY= sha1:uqMgOHNpiotLyFBt2rvsm+bJ1x8= Xref: csiph.com comp.lang.c++:86503 Juha Nieminen writes: > Richard Damon wrote: >>> Except for the quibble that a null in the source string is respected -- >>> i.e. the destination is considered to be a fixed-width field but not the >>> source. >>> >> >> Yes, it is to copy a "C String" (Null Terminated) into a fixed width field. > > Then it should have been named something entirely different. As it is now > it gets extremely easily confused with strcpy(), as if it were a "safer" > variant of it, in the same was as strncat() is a "safer" variant of > strcat(). It's already been pointed out that the source argument to strncpy() does not need to be a pointer to a (null-terminated) string. And yes, the name is misleading (also already pointed out). -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */