Date: Mon, 29 Nov 2004 11:25:14 -0800 From: Brooks Davis <brooks@one-eyed-alien.net> To: ipfw@freebsd.org Subject: strncmp usage in ipfw Message-ID: <20041129192514.GA7331@odin.ac.hmc.edu>
next in thread | raw e-mail | index | archive | help
--oyUTqETQ0mS9luUI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The ipfw program uses the following idiom quite a bit: char *var; if (!strncmp(var, "str", strlen(var))) ... I'm pretty sure that in most cases the desired comparison is actually: if (!strcmp(var, "str")) The program with the first is that all the following strings match: "" "s" "st" "str" It's remotely possible this was deliberate since we should not see the "" case and this would allow partial commands, but I'm not sure and this creates problems with maintainability. For example, if "str" were "ip" and you added a line above it containing "ip6" you'd always match "ip6" leaving difficult to spot dead code in the "ip" case. Was use of this idiom deliberate or accidental? -- Brooks --=20 Any statement of the form "X is the one, true Y" is FALSE. PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4 --oyUTqETQ0mS9luUI Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBq3eZXY6L6fI4GtQRAjViAJ9xlLMhRVB3kvwI+Fbsg+0aiCO45gCgxms2 pTYTwSo7aLVZUgHVMsqr8aw= =RDMx -----END PGP SIGNATURE----- --oyUTqETQ0mS9luUI--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041129192514.GA7331>