Subject: Re: CVS commit: src/sys/dev/pci
To: Rui Paulo <rpaulo@netbsd.org>
From: Luke Mewburn <lukem@NetBSD.org>
List: source-changes
Date: 04/18/2006 11:23:17
--azLHFNyN32YCQGCU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Apr 17, 2006 at 07:06:51PM +0000, Rui Paulo wrote:
  |=20
  | Module Name:	src
  | Committed By:	rpaulo
  | Date:		Mon Apr 17 19:06:51 UTC 2006
  |=20
  | Modified Files:
  | 	src/sys/dev/pci: if_ipw.c if_ipwvar.h
  |=20
  | Log Message:
  | Oops, 16 is not enough to store the firmware filenames, use 24.
  |=20
  |=20
  | To generate a diff of this commit:
  | cvs rdiff -r1.17 -r1.18 src/sys/dev/pci/if_ipw.c
  | cvs rdiff -r1.9 -r1.10 src/sys/dev/pci/if_ipwvar.h


I believe that it's far better style (and less error prone) to use:
	char foo[24];
	strncpy(foo, bar, sizeof(foo));
than
	char foo[24];
	strncpy(foo, bar, 24);
I.e, use sizeof() appropriately.

For that matter, I think in this situation it's even
better to use strlcpy():
	strlcpy(foo, bar, sizeof(foo));
since strncpy() does not NUL terminate if the length
of the src (excluding NUL) is the provided size, and
you're calling firmware_open() which expects the filename
to be NUL terminated.


IMHO, strncpy() should only be used when copying to a destination
where the API for that destination doesn't need a NUL termination,
such as the disklabel(5) type & pack fields, or utmp(5) fields.


cheers,
Luke.

--azLHFNyN32YCQGCU
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (NetBSD)

iD8DBQFERD+FpBhtmn8zJHIRAg+eAKC9Ggs4df1hmdkA4E4lDx6s+bwY+gCeLJH5
mdr8sJ/9vq1YMSMKYrybywA=
=IFFn
-----END PGP SIGNATURE-----

--azLHFNyN32YCQGCU--