From owner-freebsd-hackers Tue Jan 14 10:03:36 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id KAA26780 for hackers-outgoing; Tue, 14 Jan 1997 10:03:36 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id KAA26774 for ; Tue, 14 Jan 1997 10:03:12 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id KAA00168; Tue, 14 Jan 1997 10:50:18 -0700 From: Terry Lambert Message-Id: <199701141750.KAA00168@phaeton.artisoft.com> Subject: Re: unused variable in su To: bde@zeta.org.au (Bruce Evans) Date: Tue, 14 Jan 1997 10:50:18 -0700 (MST) Cc: bde@zeta.org.au, davidn@unique.usn.blaze.net.au, hackers@freebsd.org, joerg_wunsch@uriah.heep.sax.de In-Reply-To: <199701140347.OAA20727@godzilla.zeta.org.au> from "Bruce Evans" at Jan 14, 97 02:47:57 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > How about using functions strancpy(), ..., asnprintf() that abort > if the string is too long? This would be better than silently > truncating the string. It would also take less code for the > strncpy() case since null trermination would be guaranteed (else > abort). You can get the same effect using strncpy(), and presetting the terminal value in the buffer to 0, then comparing for 0 following the strncpy... ie: char mybuf[ SOMELEN]; mybuf[ SOMELEN - 1] = 0; strncpy( mybuf, src, SOMELEN); if( mybuf[ SOMELEN - 1] != 0) { /* abort ...*/ } This works because of the side-effect "...and not terminating dst if src is more than len characters long." Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.