Date: Tue, 14 Jan 1997 10:50:18 -0700 (MST) From: Terry Lambert <terry@lambert.org> To: bde@zeta.org.au (Bruce Evans) Cc: bde@zeta.org.au, davidn@unique.usn.blaze.net.au, hackers@freebsd.org, joerg_wunsch@uriah.heep.sax.de Subject: Re: unused variable in su Message-ID: <199701141750.KAA00168@phaeton.artisoft.com> In-Reply-To: <199701140347.OAA20727@godzilla.zeta.org.au> from "Bruce Evans" at Jan 14, 97 02:47:57 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199701141750.KAA00168>
