Path: utzoo!mnetor!uunet!nbires!hao!ames!amdcad!rpw3 From: rpw3@amdcad.AMD.COM (Rob Warnock) Newsgroups: comp.bugs.2bsd Subject: Re: V1.21 (strncat is broken) Message-ID: <19876@amdcad.AMD.COM> Date: 8 Jan 88 05:41:43 GMT References: <8801062002.AA15696@okeeffe.Berkeley.EDU> <4557@teddy.UUCP> Reply-To: rpw3@amdcad.UUCP (Rob Warnock) Organization: [Consultant] San Mateo, CA Lines: 27 Summary: look again: "strncat", not "strncpy" In article <4557@teddy.UUCP> you write: +--------------- | > strncat(3) doesn't truncate strings correctly. | Please don't "fix" this "bug". It is DOCUMENTED to work this way. If | the second string is longer than the size "n" supplied, then NO NULL | TERMINATER is appended. It is your MISUSE of "strncat" at fault here! | I agree, it is a pain in the ass, but this is the way strncat has | always worked since the beginning of C! +--------------- Sorry, "jpn", Keith was right the first time. The posted fix was to "strncat", NOT to "strncpy"! (Yeah, I had to look twice, myself...) True, "strncpy(dest, src, n)" does (read "MUST") leave the string unterminated if strlen(src) >= n, but "strncat(dest, src, n)" ALWAYS null-terminates (after copying at most "n" bytes). Better luck next time... ;-} Rob Warnock Systems Architecture Consultant UUCP: {amdcad,fortune,sun,attmail}!redwood!rpw3 ATTmail: !rpw3 DDD: (415)572-2607 USPS: 627 26th Ave, San Mateo, CA 94403